Cody

# Problem 43. Subset Sum

Solution 1237755

Submitted on 24 Jul 2017 by Salvatore Lacava
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))

ind = [] combo = 2 3 5 vec = 2 3 5 combo = 2 2 3 3 5 5 vec = 5 7 8 idx = 3 NoI = 3 5 ind = 2 3 combo = 2 3 5 vec = 10

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

ind = [] combo = 5 3 2 vec = 5 3 2 idx = 3 NoI = 2 ind = 3 combo = 5 5 3 3 2 2 vec = 8 7 5 combo = 5 3 2 vec = 10

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

ind = [] combo = 2 3 5 vec = 2 3 5 combo = 2 2 3 3 5 5 vec = 5 7 8 combo = 2 3 5 vec = 10

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))

ind = [] combo = 1 1 1 1 1 vec = 1 1 1 1 1 combo = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 vec = 2 2 2 2 2 2 2 2 2 2 combo = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 vec = 3 3 3 3 3 3 3 3 3 3 combo = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 vec = 4 4 4 4 4 combo = 1 1 1 1 1 vec = 5 idx = 1 NoI = 1 1 1 1 1 ind = 1 2 3 4 5

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

ind = [] combo = 1 2 3 4 100 vec = 1 2 3 4 100 idx = 5 NoI = 100 ind = 5 combo = 1 1 1 1 2 2 2 3 3 4 2 3 4 100 3 4 100 4 100 100 vec = 3 4 5 101 5 6 102 7 103 104 combo = 1 1 1 1 1 1 2 2 2 3 2 2 2 3 3 4 3 3 4 4 3 4 100 4 100 100 4 100 100 100 vec = 6 7 103 8 104 105 9 105 106 107 combo = 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 100 100 100 100 vec = 10 106 107 108 109 combo = 1 2 3 4 100 vec = 110

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

ind = [] combo = -7 -3 -2 8 5 vec = -7 -3 -2 8 5 combo = -7 -7 -7 -7 -3 -3 -3 -2 -2 8 -3 -2 8 5 -2 8 5 8 5 5 vec = -10 -9 1 -2 -5 5 2 6 3 13 combo = -7 -7 -7 -7 -7 -7 -3 -3 -3 -2 -3 -3 -3 -2 -2 8 -2 -2 8 8 -2 8 5 8 5 5 8 5 5 5 vec = -12 -2 -5 -1 -4 6 3 0 10 11 idx = 8 NoI = -3 -2 5 ind = 2 3 5 combo = -7 -7 -7 -7 -3 -3 -3 -3 -2 -2 -2 -2 8 8 8 8 5 5 5 5 vec = -4 -7 3 4 8 combo = -7 -3 -2 8 5 vec = 1

### Community Treasure Hunt

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

Start Hunting!