Cody

# Problem 43. Subset Sum

Solution 1913101

Submitted on 27 Aug 2019 by Virtual AS
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
v = [2, 3, 5]; n = 8; correct = [2, 3]; actual = subset_sum(v, n); assert(isequal(actual, correct))

bs = 7×3 logical array 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1 vs = 5 3 8 2 7 5 10 ind = 1×3 logical array 0 1 1

2   Pass
v = [5, 3, 2]; n = 2; correct = 3; actual = subset_sum(v, n); assert(isequal(actual, correct))

bs = 7×3 logical array 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1 vs = 2 3 5 5 7 8 10 ind = 1×3 logical array 0 0 1

3   Pass
v = [2, 3, 5]; n = 4; correct = []; actual = subset_sum(v, n); assert(isequal(actual, correct))

bs = 7×3 logical array 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1 vs = 5 3 8 2 7 5 10 ind = 0×3 empty logical array ind = []

4   Pass
v = [1, 1, 1, 1, 1]; n = 5; correct = [1, 2, 3, 4, 5]; actual = subset_sum(v, n); assert(isequal(actual, correct))

bs = 31×5 logical array 0 0 0 0 1 0 0 0 1 0 0 0 0 1 1 0 0 1 0 0 0 0 1 0 1 0 0 1 1 0 0 0 1 1 1 0 1 0 0 0 0 1 0 0 1 0 1 0 1 0 0 1 0 1 1 0 1 1 0 0 0 1 1 0 1 0 1 1 1 0 0 1 1 1 1 1 0 0 0 0 1 0 0 0 1 1 0 0 1 0 1 0 0 1 1 1 0 1 0 0 1 0 1 0 1 1 0 1 1 0 1 0 1 1 1 1 1 0 0 0 1 1 0 0 1 1 1 0 1 0 1 1 0 1 1 1 1 1 0 0 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 vs = Columns 1 through 29 1 1 2 1 2 2 3 1 2 2 3 2 3 3 4 1 2 2 3 2 3 3 4 2 3 3 4 3 4 Columns 30 through 31 4 5 ind = 1×5 logical array 1 1 1 1 1

5   Pass
v = [1, 2, 3, 4, 100]; n = 100; correct = 5; actual = subset_sum(v, n); assert(isequal(actual, correct))

bs = 31×5 logical array 0 0 0 0 1 0 0 0 1 0 0 0 0 1 1 0 0 1 0 0 0 0 1 0 1 0 0 1 1 0 0 0 1 1 1 0 1 0 0 0 0 1 0 0 1 0 1 0 1 0 0 1 0 1 1 0 1 1 0 0 0 1 1 0 1 0 1 1 1 0 0 1 1 1 1 1 0 0 0 0 1 0 0 0 1 1 0 0 1 0 1 0 0 1 1 1 0 1 0 0 1 0 1 0 1 1 0 1 1 0 1 0 1 1 1 1 1 0 0 0 1 1 0 0 1 1 1 0 1 0 1 1 0 1 1 1 1 1 0 0 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 vs = Columns 1 through 29 100 4 104 3 103 7 107 2 102 6 106 5 105 9 109 1 101 5 105 4 104 8 108 3 103 7 107 6 106 Columns 30 through 31 10 110 ind = 1×5 logical array 0 0 0 0 1

6   Pass
v = [-7, -3, -2, 8, 5]; n = 0; correct = [2, 3, 5]; actual = subset_sum(v, n); assert(isequal(actual, correct))

bs = 31×5 logical array 0 0 0 0 1 0 0 0 1 0 0 0 0 1 1 0 0 1 0 0 0 0 1 0 1 0 0 1 1 0 0 0 1 1 1 0 1 0 0 0 0 1 0 0 1 0 1 0 1 0 0 1 0 1 1 0 1 1 0 0 0 1 1 0 1 0 1 1 1 0 0 1 1 1 1 1 0 0 0 0 1 0 0 0 1 1 0 0 1 0 1 0 0 1 1 1 0 1 0 0 1 0 1 0 1 1 0 1 1 0 1 0 1 1 1 1 1 0 0 0 1 1 0 0 1 1 1 0 1 0 1 1 0 1 1 1 1 1 0 0 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 vs = Columns 1 through 29 5 8 13 -2 3 6 11 -3 2 5 10 -5 0 3 8 -7 -2 1 6 -9 -4 -1 4 -10 -5 -2 3 -12 -7 Columns 30 through 31 -4 1 ind = 1×5 logical array 0 1 1 0 1

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!