Cody

# Problem 660. Find a subset that divides the vector into equal halves

Solution 1370682

Submitted on 6 Dec 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
x = [1 2 3 4 5 6 7]; xi = split_it(x); assert(isequal(sum(x(xi)),sum(x)/2));

validCombins = 1 2 3 4 5 6 7 validCombins = 1 2 1 3 1 4 1 5 1 6 1 7 2 3 2 4 2 5 2 6 2 7 3 4 3 5 3 6 3 7 4 5 4 6 4 7 5 6 5 7 6 7 validCombins = 1 2 3 1 2 4 1 2 5 1 2 6 1 2 7 1 3 4 1 3 5 1 3 6 1 3 7 1 4 5 1 4 6 1 4 7 1 5 6 1 5 7 1 6 7 2 3 4 2 3 5 2 3 6 2 3 7 2 4 5 2 4 6 2 4 7 2 5 6 2 5 7 2 6 7 3 4 5 3 4 6 3 4 7 3 5 6 3 5 7 3 6 7 4 5 6 4 5 7 4 6 7 5 6 7

2   Pass
x = [2 2 2 2 2 2]; xi = split_it(x); assert(isequal(sum(x(xi)),sum(x)/2));

validCombins = 1 2 3 4 5 6 validCombins = 1 2 1 3 1 4 1 5 1 6 2 3 2 4 2 5 2 6 3 4 3 5 3 6 4 5 4 6 5 6 validCombins = 1 2 3 1 2 4 1 2 5 1 2 6 1 3 4 1 3 5 1 3 6 1 4 5 1 4 6 1 5 6 2 3 4 2 3 5 2 3 6 2 4 5 2 4 6 2 5 6 3 4 5 3 4 6 3 5 6 4 5 6

3   Pass
x = [2 5 4 5 4]; xi = split_it(x); assert(isequal(sum(x(xi)),sum(x)/2));

validCombins = 1 2 3 4 5 validCombins = 1 2 1 3 1 4 1 5 2 3 2 4 2 5 3 4 3 5 4 5

4   Pass
x = [1 3 1 1 9 7]; xi = split_it(x); assert(isequal(sum(x(xi)),sum(x)/2));

validCombins = 1 2 3 4 5 6 validCombins = 1 2 1 3 1 4 1 5 1 6 2 3 2 4 2 5 2 6 3 4 3 5 3 6 4 5 4 6 5 6 validCombins = 1 2 3 1 2 4 1 2 5 1 2 6 1 3 4 1 3 5 1 3 6 1 4 5 1 4 6 1 5 6 2 3 4 2 3 5 2 3 6 2 4 5 2 4 6 2 5 6 3 4 5 3 4 6 3 5 6 4 5 6

5   Pass
x = primes(100); xi = split_it(x); assert(isequal(sum(x(xi)),sum(x)/2));

validCombins = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 validCombins = 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 9 8 10 8 11 8 12 8 13 8 14 8 15 8 16 8 17 8 18 8 19 8 20 8 21 8 22 8 23 8 24 8 25 9 10 9 11 9 12 9 13 9 14 9 15 9 16 9 17 9 18 9 19 9 20 9 21 9 22 9 23 9 24 9 25 10 11 10 12 10 13 10 14 10 15 10 16 10 17 10 18 10 19 10 20 10 21 10 22 10 23 10 24 10 25 11 12 11 13 11 14 11 15 11 16 11 17 11 18 11 19 11 20 11 21 11 22 11 23 11 24 11 25 12 13 12 14 12 15 12 16 12 17 12 18 12 19 12 20 12 21 12 22 12 23 12 24 12 25 13 14 13 15 13 16 13 17 13 18 13 19 13 20 13 21 13 22 13 23 13 24 13 25 14 15 14 16 14 17 14 18 14 19 14 20 14 21 14 22 14 23 14 24 14 25 15 16 15 17 15 18 15 19 15 20 15 21 15 22 15 23 15 24 15 25 16 17 16 18 16 19 16 20 16 21 16 22 16 23 16 24 16 25 17 18 17 19 17 20 17 21 17 22 17 23 17 24 17 25 18 19 18 20 18 21 18 22 18 23 18 24 18 25 19 20 19 21 19 22 19 23 19 24 19 25 20 21 20 22 20 23 20 24 20 25 21 22 21 23 21 24 21 25 22 23 22 24 22 25 23 24 23 25 24 25 validCombins = 1 2 3 1 2 4 1 2 5 1 2 6 1 2 7 1 2 8 1 2 9 1 2 10 1 2 11 1 2 12 1 2 13 1 2 14 1 2 15 1 2 16 1 2 17 1 2 18 1 2 19 1 2 20 1 2 21 1 2 22 1 2 23 1 2 24 1 2 25 1 3 4 1 3 5 1 3 6 1 3 7 1 3 8 1 3 9 1 3 10 1 3 11 1 3 12 1 3 13 1 3 14 1 3 15 1 3 16 1 3 17 1 3 18 1 3 19 1 3 20 1 3 21 1 3 22 1 3 23 1 3 24 1 3 25 1 4 5 1 4 6 1 4 7 1 4 8 1 4 9 1 4 10 1 4 11 1 4 12 1 4 13 1 4 14 1 4 15 1 4 16 1 4 17 1 4 18 1 4 19 1 4 20 1 4 21 1 4 22 1 4 23 1 4 24 1 4 25 1 5 6 1 5 7 1 5 8 1 5 9 1 5 10 1 5 11 1 5 12 1 5 13 1 5 14 1 5 15 1 5 16 1 5 17 1 5 18 1 5 19 1 5 20 1 5 21 1 5 22 1 5 23 1 5 24 1 5 25 1 6 7 1 6 8 1 6 9 1 6 10 1 6 11 1 6 12 1 6 13 1 6 14 1 6 15 1 6 16 1 6 17 1 6 18 1 6 19 1 6 20 1 6 21 1 6 22 1 6 23 1 6 24 1 6 25 1 7 8 1 7 9 1 7 10 1 7 11 1 7 12 1 7 13 1 7 14 1 7 15 1 7 16 1 7 17 1 7 18 1 7 19 1 7 20 1 7 21 1 7 22 1 7 23 1 7 24 1 7 25 1 8 9 1 8 10 1 8 11 1 8 12 1 8 13 1 8 14 1 8 15 1 8 16 1 8 17 1 8 18 1 8 19 1 8 20 1 8 21 1 8 22 1 8 23 1 8 24 1 8 25 1 9 10 1 9 11 1 9 12 1 9 13 1 9 14 1 9 15 1 9 16 1 9 17 1 9 18 1 9 19 1 9 20 1 9 21 1 9 22 1 9 23 1 9 24 1 9 25 1 10 11 1 10 12 1 10 13 1 10 14 1 10 15 1 10 16 1 10 17 1 10 18 1 10 19 1 10 20 1 10 21 1 10 22 1 10 23 1 10 24 1 10 25 1 11 12 1 11 13 1 11 14 1 11 15 1 11 16 1 11 17 1 11 18 1 11 19 1 11 20 1 11 21 1 11 22 1 11 23 1 11 24 1 11 25 1 12 13 1 12 14 1 12 15 1 12 16 1 12 17 1 12 18 1 12 19 1 12 20 1 12 21 1 12 22 1 12 23 1 12 24 1 12 25 1 13 14 1 13 15 1 13 16 1 13 17 1 13 18 1 13 19 1 13 20 1 13 21 1 13 22 1 13 23 1 13 24 1 13 25 1 14 15 1 14 16 1 14 17 1 14 18 1 14 19 1 14 20 1 14 21 1 14 22 1 14 23 1 14 24 1 14 25 1 15 16 1 15 17 1 15 18 1 15 19 1 15 20 1 15 21 1 15 22 1 15 23 1 15 24 1 15 25 1 16 17 1 16 18 1 16 19 1 16 20 1 16 21 1 16 22 1 16 23 1 16 24 1 16 25 1 17 18 1 17 19 1 17 20 1 17 21 1 17 22 1 17 23 1 17 24 1 17 25 1 18 19 1 18 20 1 18 21 1 18 22 1 18 23 1 18 24 1 18 25 1 19 20 1 19 21 1 19 22 1 19 23 1 19 24 1 19 25 1 20 21 1 20 22 1 20 23 1 20 24 1 20 25 1 21 22 1 21 23 1 21 24 1 21 25 1 22 23 1 22 24 1 22 25 1 23 24 1 23 25 1 24 25 2 3 4 2 3 5 2 3 6 2 3 7 2 3 8 2 3 9 2 3 10 2 3 11 2 3 12 2 3 13 2 3 14 2 3 15 2 3 16 2 3 17 2 3 18 2 3 19 2 3 20 2 3 21 2 3 22 2 3 23 2 3 24 2 3 25 2 4 5 2 4 6 2 4 7 2 4 8 2 4 9 2 4 10 2 4 11 2 4 12 2 4 13 2 4 14 2 4 15 ...