Cody

# Problem 43. Subset Sum

Solution 1917209

Submitted on 31 Aug 2019 by Adi Ben Hayun
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 = [] index_perms = 0 0 1 0 1 0 0 0 1 0 1 0 1 0 0 1 0 0 indices = 0 0 1 indices = 0 1 0 indices = 0 0 1 indices = 0 1 0 indices = 1 0 0 indices = 1 0 0 index_perms = 0 1 1 0 1 1 1 0 1 1 1 0 1 0 1 1 1 0 indices = 0 1 1 ind = 2 ind = 2 3

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

ind = [] index_perms = 0 0 1 0 1 0 0 0 1 0 1 0 1 0 0 1 0 0 indices = 0 0 1 ind = 3

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

ind = [] index_perms = 0 0 1 0 1 0 0 0 1 0 1 0 1 0 0 1 0 0 indices = 0 0 1 indices = 0 1 0 indices = 0 0 1 indices = 0 1 0 indices = 1 0 0 indices = 1 0 0 index_perms = 0 1 1 0 1 1 1 0 1 1 1 0 1 0 1 1 1 0 indices = 0 1 1 indices = 0 1 1 indices = 1 0 1 indices = 1 1 0 indices = 1 0 1 indices = 1 1 0 index_perms = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 indices = 1 1 1 indices = 1 1 1 indices = 1 1 1 indices = 1 1 1 indices = 1 1 1 indices = 1 1 1

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 = [] index_perms = 0 0 0 0 1 0 0 0 1 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 1 0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 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 1 0 0 indices = 0 0 1 0 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 1 0 0 indices = 0 0 1 0 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 1 0 0 indices = 0 0 1 0 0 indices = 0 1 0 0 0 indices = 0 1 0 0 0 indices = 0 1 0 0 0 indices = 0 1 0 0 0 indices = 0 1 0 0 0 indices = 0 1 0 0 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 1 0 0 indices = 0 0 1 0 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 1 0 0 indices = 0 0 1 0 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 1 0 0 indices = 0 0 1 0 0 indices = 0 1 0 0 0 indices = 0 1 0 0 0 indices = 0 1 0 0 0 indices = 0 1 0 0 0 indices = 0 1 0 0 0 indices = 0 1 0 0 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 1 0 0 indices = 0 0 1 0 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 1 0 0 indices = 0 0 1 0 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 1 0 0 indices = 0 0 1 0 0 indices = 0 1 0 0 0 indices = 0 1 0 0 0 indices = 0 1 0 0 0 indices = 0 1 0 0 0 indices = 0 1 0 0 0 indices = 0 1 0 0 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 1 0 0 indices = 0 0 1 0 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 1 0 0 indices = 0 0 1 0 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 1 0 0 indices = 0 0 1 0 0 indices = 0 1 0 0 0 indices = 0 1 0 0 0 indices = 0 1 0 0 0 indices = 0 1 0 0 0 indices = 0 1 0 0 0 indices = 0 1 0 0 0 indices = 1 0 0 0 0 indices = 1 0 0 0 0 indices = 1 0 0 0 0 indices = 1 0 0 0 0 indices = 1 0 0 0 0 indices = 1 0 0 0 0 indices = 1 0 0 0 0 indices = 1 0 0 0 0 indices = 1 0 0 0 0 indices = 1 0 0 0 0 indices = 1 0 0 0 0 indices = 1 0 0 0 0 indices = 1 0 0 0 0 indices = 1 0 0 0 0 indices = 1 0 0 0 0 indices = 1 0 0 0 0 indices = 1 0 0 0 0 indices = 1 0 0 0 0 indices = 1 0 0 0 0 indices = 1 0 0 0 0 indices = 1 0 0 0 0 indices = 1 0 0 0 0 indices = 1 0 0 0 0 indices = 1 0 0 0 0 index_perms = 0 0 0 1 1 0 0 0 1 1 0 0 1 0 1 0 0 1 1 0 0 0 1 0 1 0 0 1 1 0 0 0 0 1 1 0 0 0 1 1 0 0 1 0 1 0 0 1 1 0 0 0 1 0 1 0 0 1 1 0 0 1 0 0 1 0 1 0 1 0 0 1 0 0 1 0 1 0 1 0 0 1 1 0 0 0 1 1 0 0 0 1 0 0 1 0 1 0 1 0 0 1 0 0 1 0 1 0 1 0 0 1 1 0 0 0 1 1 0 0 0 0 0 1 1 0 0 0 1 1 0 0 1 0 1 0 0 1 1 0 0 0 1 0 1 0 0 1 1 0 0 0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0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 1 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 1 0 0 indices = 0 0 1 0 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 1 0 0 indices = 0 0 1 0 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 1 0 0 indices = 0 0 1 0 0 indices = 0 1 0 0 0 indices = 0 1 0 0 0 indices = 0 1 0 0 0 indices = 0 1 0 0 0 indices = 0 1 0 0 0 indices = 0 1 0 0 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 1 0 0 indices = 0 0 1 0 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 1 0 0 indices = 0 0 1 0 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 1 0 0 indices = 0 0 1 0 0 indices = 0 1 0 0 0 indices = 0 1 0 0 0 indices = 0 1 0 0 0 indices = 0 1 0 0 0 indices = 0 1 0 0 0 indices = 0 1 0 0 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 1 0 0 indices = 0 0 1 0 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 1 0 0 indices = 0 0 1 0 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 1 0 0 indices = 0 0 1 0 0 indices = 0 1 0 0 0 indices = 0 1 0 0 0 indices = 0 1 0 0 0 indices = 0 1 0 0 0 indices = 0 1 0 0 0 indices = 0 1 0 0 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 1 0 0 indices = 0 0 1 0 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 1 0 0 indices = 0 0 1 0 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 0 0 1 indices = 0 0 0 1 0 indices = 0 0 1 0 0 indices = 0 0 1 0 0 indices = 0 1 0 0 0 indices = 0 1 0 0 0 indices = 0 1 0 0 0 indices = 0 1 0 0 0 indices = 0 1 0 0 0 indices = 0 1 0 0 0 indices = 1 0 0 0 0 indices = 1 0 0 0 0 indices = 1 0 0 0 0 indices = 1 0 0 0 0 indices = 1 0 0 0 0 indices = 1 0 0 0 0 indices = 1 0 0 0 0 indices = 1 0 0 0 0 indices = 1 0 0 0 0 indices = 1 0 0 0 0 indices = 1 0 0 0 0 indices = 1 0 0 0 0 indices = 1 0 0 0 0 indices = 1 0 0 0 0 indices = 1 0 0 0 0 indices = 1 0 0 0 0 indices = 1 0 0 0 0 indices = 1 0 0 0 0 indices = 1 0 0 0 0 indices = 1 0 0 0 0 indices = 1 0 0 0 0 indices = 1 0 0 0 0 indices = 1 0 0 0 0 indices = 1 0 0 0 0 index_perms = 0 0 0 1 1 0 0 0 1 1 0 0 1 0 1 0 0 1 1 0 0 0 1 0 1 0 0 1 1 0 0 0 0 1 1 0 0 0 1 1 0 0 1 0 1 0 0 1 1 0 0 0 1 0 1 0 0 1 1 0 0 1 0 0 1 0 1 0 1 0 0 1 0 0 1 0 1 0 1 0 0 1 1 0 0 0 1 1 0 0 0 1 0 0 1 0 1 0 1 0 0 1 0 0 1 0 1 0 1 0 0 1 1 0 0 0 1 1 0 0 0 0 0 1 1 0 0 0 1 1 0 0 1 0 1 0 0 1 1 0 0 0 1 0 1 0 0 1 1 0 0 0 0 ...