Cody

# Problem 47415. List ways to reach a target sum

Solution 3580260

Submitted on 8 Nov 2020 by William
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
x = [3 6 10 11 15 16 16 20]; s = 43; y = sumToTarget(x,s); h = histcounts(cellfun(@sum,y),43:98); h_correct = [3 4 7 6 6 4 4 6 6 7 4 3 6 5 5 4 2 5 6 5 4 3 4 4 4 4 1 3 4 3 2 1 2 2 2 3 1 1 3 1 1 1 0 1 1 1 0 0 1 0 0 1 0 0 1]; assert(isequal(h,h_correct))

2   Pass
x = [3 6 11 15 16 20]; s = 17; y = sumToTarget(x,s); h = histcounts(cellfun(@sum,y),17:56); h_correct = [1 1 1 2 1 1 1 1 1 2 1 0 2 1 2 1 1 2 2 2 2 1 1 2 1 2 0 1 2 1 1 1 1 1 2 1 1 1 2]; assert(isequal(h,h_correct))

3   Pass
x = [3 11 15 16]; s = -9; y = sumToTarget(x,s); len_correct = 16; assert(isequal(length(y),len_correct))

4   Pass
x = [3 11 15 16]; s = 306-279; y = sumToTarget(x,s); sum_correct = [27 29 30 31 34 42 45]; assert(isequal(sort(cellfun(@sum,y)),sum_correct))

### Community Treasure Hunt

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

Start Hunting!