Cody

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

Solution 2096532

Submitted on 17 Jan 2020 by Asif Newaz
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));

a = 14 b = 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 e = 3 4 5 6 7 8 5 6 7 8 9 7 8 9 10 9 10 11 11 12 13 f = 0×1 empty double column vector b = 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 e = 6 7 8 9 10 8 9 10 11 10 11 12 12 13 14 9 10 11 12 11 12 13 13 14 15 12 13 14 14 15 16 15 16 17 18 f = 15 24 28 29 g = 1 6 7 v = 1 h = 1 v = 6 h = 1 6 v = 7 h = 1 6 7

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

a = 6 b = 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 e = 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 f = 0×1 empty double column vector b = 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 e = 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 f = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 g = 2 2 2 v = 1 2 3 4 5 6 h = 1 v = 1 2 3 4 5 6 h = 1 1 v = 1 2 3 4 5 6 h = 1 1 1

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

a = 10 b = 2 5 2 4 2 5 2 4 5 4 5 5 5 4 4 5 4 4 5 4 e = 7 6 7 6 9 10 9 9 8 9 f = 6 g = 5 5 v = 2 4 h = 2 v = 2 4 h = 2 2

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

a = 11 b = 1 3 1 1 1 1 1 9 1 7 3 1 3 1 3 9 3 7 1 1 1 9 1 7 1 9 1 7 9 7 e = 4 2 2 10 8 4 4 12 10 2 10 8 10 8 16 f = 0×1 empty double column vector b = 1 3 1 1 3 1 1 3 9 1 3 7 1 1 1 1 1 9 1 1 7 1 1 9 1 1 7 1 9 7 3 1 1 3 1 9 3 1 7 3 1 9 3 1 7 3 9 7 1 1 9 1 1 7 1 9 7 1 9 7 e = 5 5 13 11 3 11 9 11 9 17 5 13 11 13 11 19 11 9 17 17 f = 4 6 8 13 15 17 g = 1 3 7 v = 1 3 4 h = 1 v = 2 h = 1 2 v = 6 h = 1 2 6

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

a = 530 b = 2 3 2 5 2 7 2 11 2 13 2 17 2 19 2 23 2 29 2 31 2 37 2 41 2 43 2 47 2 53 2 59 2 61 2 67 2 71 2 73 2 79 2 83 2 89 2 97 3 5 3 7 3 11 3 13 3 17 3 19 3 23 3 29 3 31 3 37 3 41 3 43 3 47 3 53 3 59 3 61 3 67 3 71 3 73 3 79 3 83 3 89 3 97 5 7 5 11 5 13 5 17 5 19 5 23 5 29 5 31 5 37 5 41 5 43 5 47 5 53 5 59 5 61 5 67 5 71 5 73 5 79 5 83 5 89 5 97 7 11 7 13 7 17 7 19 7 23 7 29 7 31 7 37 7 41 7 43 7 47 7 53 7 59 7 61 7 67 7 71 7 73 7 79 7 83 7 89 7 97 11 13 11 17 11 19 11 23 11 29 11 31 11 37 11 41 11 43 11 47 11 53 11 59 11 61 11 67 11 71 11 73 11 79 11 83 11 89 11 97 13 17 13 19 13 23 13 29 13 31 13 37 13 41 13 43 13 47 13 53 13 59 13 61 13 67 13 71 13 73 13 79 13 83 13 89 13 97 17 19 17 23 17 29 17 31 17 37 17 41 17 43 17 47 17 53 17 59 17 61 17 67 17 71 17 73 17 79 17 83 17 89 17 97 19 23 19 29 19 31 19 37 19 41 19 43 19 47 19 53 19 59 19 61 19 67 19 71 19 73 19 79 19 83 19 89 19 97 23 29 23 31 23 37 23 41 23 43 23 47 23 53 23 59 23 61 23 67 23 71 23 73 23 79 23 83 23 89 23 97 29 31 29 37 29 41 29 43 29 47 29 53 29 59 29 61 29 67 29 71 29 73 29 79 29 83 29 89 29 97 31 37 31 41 31 43 31 47 31 53 31 59 31 61 31 67 31 71 31 73 31 79 31 83 31 89 31 97 37 41 37 43 37 47 37 53 37 59 37 61 37 67 37 71 37 73 37 79 37 83 37 89 37 97 41 43 41 47 41 53 41 59 41 61 41 67 41 71 41 73 41 79 41 83 41 89 41 97 43 47 43 53 43 59 43 61 43 67 43 71 43 73 43 79 43 83 43 89 43 97 47 53 47 59 47 61 47 67 47 71 47 73 47 79 47 83 47 89 47 97 53 59 53 61 53 67 53 71 53 73 53 79 53 83 53 89 53 97 59 61 59 67 59 71 59 73 59 79 59 83 59 89 59 97 61 67 61 71 61 73 61 79 61 83 61 89 61 97 67 71 67 73 67 79 67 83 67 89 67 97 71 73 71 79 71 83 71 89 71 97 73 79 73 83 73 89 73 97 79 83 79 89 79 97 83 89 83 97 89 97 e = 5 7 9 13 15 19 21 25 31 33 39 43 45 49 55 61 63 69 73 75 81 85 91 99 8 10 14 16 20 22 26 32 34 40 44 46 50 56 62 64 70 74 76 82 86 92 100 12 16 18 22 24 28 34 36 42 46 48 52 58 64 66 72 76 78 84 88 94 102 18 20 24 26 30 36 38 44 48 50 54 60 66 68 74 78 80 86 90 96 104 24 28 30 34 40 42 48 52 54 58 64 70 72 78 82 84 90 94 100 108 30 32 36 42 44 50 54 56 60 66 72 74 80 84 86 92 96 102 110 36 40 46 48 54 58 60 64 70 76 78 84 88 90 96 100 106 114 42 48 50 56 60 62 66 72 78 80 86 90 92 98 102 108 116 52 54 60 64 66 70 76 82 84 90 94 96 102 106 112 120 60 66 70 72 76 82 88 90 96 100 102 108 112 118 126 68 72 74 78 84 90 92 98 102 104 110 114 120 128 78 80 84 90 96 98 104 108 110 116 120 126 134 84 88 94 100 102 108 112 114 120 124 130 138 90 96 102 104 110 114 116 122 126 132 140 100 106 108 114 118 120 126 130 136 144 112 114 120 124 126 132 136 142 150 120 126 130 132 138 142 148 156 128 132 134 140 144 150 158 138 140 146 150 156 164 144 150 154 160 168 152 156 162 170 162 168 176 172 180 186 f = 0×1 empty double column vector b = 2 3 5 2 3 7 2 3 11 2 3 13 2 3 17 2 3 19 2 3 23 2 3 29 2 3 31 2 3 37 2 3 41 2 3 43 2 3 47 2 3 53 2 3 59 2 3 61 2 3 67 2 3 71 2 3 73 2 3 79 2 3 83 2 3 89 2 3 97 2 5 7 2 5 11 2 5 13 2 5 17 2 5 19 2 5 23 2 5 29 2 5 31 2 5 37 2 5 41 2 5 43 2 5 47 2 5 53 2 5 59 2 5 61 2 5 67 2 5 71 2 5 73 2 5 79 2 5 83 2 5 89 2 5 97 2 7 11 2 7 13 2 7 17 2 7 19 2 7 23 2 7 29 2 7 31 2 7 37 2 7 41 2 7 43 2 7 47 2 7 53 2 7 59 2 7 61 2 7 67 2 7 71 2 7 73 2 7 79 2 7 83 2 7 89 2 7 97 2 11 13 2 11 17 2 11 19 2 11 23 2 11 29 2 11 31 2 11 37 2 11 41 2 11 43 2 11 47 2 11 53 2 11 59 2 11 61 2 11 67 2 11 71 2 11 73 2 11 79 2 11 83 2 11 89 2 11 97 2 13 17 2 13 19 2 13 23 2 13 29 2 13 31 2 13 37 2 13 41 2 13 43 2 13 47 2 13 53 2 13 59 2 13 61 2 13 67 2 13 71 2 13 73 2 13 79 2 13 83 2 13 89 2 13 97 2 17 19 2 17 23 2 17 29 2 17 31 2 17 37 2 17 41 2 17 43 2 17 47 2 17 53 2 17 59 2 17 61 2 17 67 2 17 71 2 17 73 2 17 79 2 17 83 2 17 89 2 17 97 2 19 23 2 19 29 2 19 31 2 19 37 2 19 41 2 19 43 2 19 47 2 19 53 2 19 59 2 19 61 2 19 67 2 19 71 2 19 73 2 19 79 2 19 83 2 19 89 2 19 97 2 23 29 2 23 31 2 23 37 2 23 41 2 23 43 2 23 47 2 23 53 2 23 59 2 23 61 2 23 67 2 23 71 2 23 73 2 23 79 2 23 83 2 23 89 2 23 97 2 29 31 2 29 37 2 29 41 2 29 43 2 29 47 2 29 53 2 29 59 2 29 61 2 29 67 2 29 71 2 29 73 2 29 79 2 29 83 2 29 89 2 29 97 2 31 37 2 31 41 2 31 43 2 31 47 2 31 53 2 31 59 2 31 61 2 31 67 2 31 71 2 31 73 2 31 79 2 31 83 2 31 89 2 31 97 2 37 41 2 37 43 2 37 47 2 37 53 2 37 59 2 37 61 2 37 67 2 37 71 2 37 73 2 37 79 2 37 83 2 37 89 2 37 97 2 41 43 2 41 47 2 41 53 2 41 59 2 41 61 2 41 67 2 41 71 2 41 73 2 41 ...