Cody

Problem 43. Subset Sum

Solution 1163376

Submitted on 14 Apr 2017 by David Verrelli
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))

binIdx = '001' binIdx = '010' binIdx = '011' ind = 2 3

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

binIdx = '001' ind = 3

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

binIdx = '001' binIdx = '010' binIdx = '011' binIdx = '100' binIdx = '101' binIdx = '110' binIdx = '111'

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

binIdx = '00001' binIdx = '00010' binIdx = '00011' binIdx = '00100' binIdx = '00101' binIdx = '00110' binIdx = '00111' binIdx = '01000' binIdx = '01001' binIdx = '01010' binIdx = '01011' binIdx = '01100' binIdx = '01101' binIdx = '01110' binIdx = '01111' binIdx = '10000' binIdx = '10001' binIdx = '10010' binIdx = '10011' binIdx = '10100' binIdx = '10101' binIdx = '10110' binIdx = '10111' binIdx = '11000' binIdx = '11001' binIdx = '11010' binIdx = '11011' binIdx = '11100' binIdx = '11101' binIdx = '11110' binIdx = '11111' 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))

binIdx = '00001' 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))

binIdx = '00001' binIdx = '00010' binIdx = '00011' binIdx = '00100' binIdx = '00101' binIdx = '00110' binIdx = '00111' binIdx = '01000' binIdx = '01001' binIdx = '01010' binIdx = '01011' binIdx = '01100' binIdx = '01101' ind = 2 3 5

Community Treasure Hunt

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

Start Hunting!