Cody

# Problem 43. Subset Sum

Solution 1657608

Submitted on 24 Oct 2018 by Bob Tivnan
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 = [] m = 2 2 3 3 5 5 p = 0×1 empty double column vector m = 2 3 5 2 5 7 3 5 8 p = 3 n = 3 5 ind = 2 3

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

ind = [] m = 5 5 3 3 2 2 p = 3 n = 2 ind = 3

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

ind = [] m = 2 2 3 3 5 5 p = 0×1 empty double column vector m = 2 3 5 2 5 7 3 5 8 p = 0×1 empty double column vector m = 2 3 5 10 p = []

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 = [] m = 1 1 1 1 1 1 1 1 1 1 p = 0×1 empty double column vector m = 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 1 2 p = 0×1 empty double column vector m = 1 1 1 3 1 1 1 3 1 1 1 3 1 1 1 3 1 1 1 3 1 1 1 3 1 1 1 3 1 1 1 3 1 1 1 3 1 1 1 3 p = 0×1 empty double column vector m = 1 1 1 1 4 1 1 1 1 4 1 1 1 1 4 1 1 1 1 4 1 1 1 1 4 p = 0×1 empty double column vector m = 1 1 1 1 1 5 p = 1 n = 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 = [] m = 1 1 2 2 3 3 4 4 100 100 p = 5 n = 100 ind = 5

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

ind = [] m = -7 -7 -3 -3 -2 -2 8 8 5 5 p = 0×1 empty double column vector m = -7 -3 -10 -7 -2 -9 -7 8 1 -7 5 -2 -3 -2 -5 -3 8 5 -3 5 2 -2 8 6 -2 5 3 8 5 13 p = 0×1 empty double column vector m = -7 -3 -2 -12 -7 -3 8 -2 -7 -3 5 -5 -7 -2 8 -1 -7 -2 5 -4 -7 8 5 6 -3 -2 8 3 -3 -2 5 0 -3 8 5 10 -2 8 5 11 p = 8 n = -3 -2 5 ind = 2 3 5

### Community Treasure Hunt

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

Start Hunting!