Cody

# Problem 44940. Get Next Combination

Solution 2027281

Submitted on 19 Nov 2019
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
assert(isequal(nextComb([1 2 3],5),[1 2 4]))

2   Pass
assert(isequal(nextComb([2 4 5],5),[3 4 5]))

3   Fail
assert(isequal(nextComb([3 4 5],5),[3 4 5])) % if it is the last combination in the list; return itself

Index in position 1 exceeds array bounds (must not exceed 10). Error in nextComb (line 5) y = comb(idx+1,:); Error in Test3 (line 1) assert(isequal(nextComb([3 4 5],5),[3 4 5])) % if it is the last combination in the list; return itself

4   Pass
assert(isequal(nextComb([1 3 4 5],5),[2 3 4 5]))

5   Pass
assert(isequal(nextComb([5 6 7 10],10),[5 6 8 9]))

6   Pass
assert(isequal(nextComb([2 3 4 5 10],10),[2 3 4 6 7]))

7   Pass
assert(isequal(nextComb([5 7 8 9 10],10),[6 7 8 9 10]))

8   Pass
assert(isequal(nextComb([8 10 17 19 20],20),[8 10 18 19 20]))

9   Pass
assert(isequal(nextComb([11 13 17 18 20],20),[11 13 17 19 20]))

10   Pass
assert(isequal(nextComb([7 8 13 17 19 20],20),[7 8 13 18 19 20]))

11   Pass
assert(isequal(nextComb([10 11 17 18 19 20],20),[10 12 13 14 15 16]))

12   Pass
assert(isequal(nextComb([12 16 17 18 19 20],20),[13 14 15 16 17 18]))

13   Fail
assert(isequal(nextComb([1:6 9 14 19 20 21 23 26 29 30],30),[1:6 9 14 19 20 21 23 27 28 29]))

Error using zeros Requested 155117520x15 (17.3GB) array exceeds maximum array size preference. Creation of arrays greater than this limit may take a long time and cause MATLAB to become unresponsive. See array size limit or preference panel for more information. Error in nchoosek>combs (line 164) P = zeros(total, k, 'like', v); Error in nchoosek (line 123) c = combs(v,k); Error in nextComb (line 2) comb = nchoosek(1:n,length(vec)); Error in Test13 (line 1) assert(isequal(nextComb([1:6 9 14 19 20 21 23 26 29 30],30),[1:6 9 14 19 20 21 23 27 28 29]))

14   Fail
assert(isequal(nextComb([1:5 7 11 13 15 18 19 21 22 27 29],30),[1:5 7 11 13 15 18 19 21 22 27 30]))

Error using zeros Requested 155117520x15 (17.3GB) array exceeds maximum array size preference. Creation of arrays greater than this limit may take a long time and cause MATLAB to become unresponsive. See array size limit or preference panel for more information. Error in nchoosek>combs (line 164) P = zeros(total, k, 'like', v); Error in nchoosek (line 123) c = combs(v,k); Error in nextComb (line 2) comb = nchoosek(1:n,length(vec)); Error in Test14 (line 1) assert(isequal(nextComb([1:5 7 11 13 15 18 19 21 22 27 29],30),[1:5 7 11 13 15 18 19 21 22 27 30]))

15   Fail
assert(isequal(nextComb([1:4 6 10 13 14 15 18 19 20 23 24 30],30),[1:4 6 10 13 14 15 18 19 20 23 25 26]))

Error using zeros Requested 155117520x15 (17.3GB) array exceeds maximum array size preference. Creation of arrays greater than this limit may take a long time and cause MATLAB to become unresponsive. See array size limit or preference panel for more information. Error in nchoosek>combs (line 164) P = zeros(total, k, 'like', v); Error in nchoosek (line 123) c = combs(v,k); Error in nextComb (line 2) comb = nchoosek(1:n,length(vec)); Error in Test15 (line 1) assert(isequal(nextComb([1:4 6 10 13 14 15 18 19 20 23 24 30],30),[1:4 6 10 13 14 15 18 19 20 23 25 26]))

16   Fail
assert(isequal(nextComb([1:17 19 23 27 33 40 42 48 50],50),[1:17 19 23 27 33 40 42 49 50]))

Error using zeros Maximum variable size allowed by the program is exceeded. Error in nchoosek>combs (line 164) P = zeros(total, k, 'like', v); Error in nchoosek (line 123) c = combs(v,k); Error in nextComb (line 2) comb = nchoosek(1:n,length(vec)); Error in Test16 (line 1) assert(isequal(nextComb([1:17 19 23 27 33 40 42 48 50],50),[1:17 19 23 27 33 40 42 49 50]))

17   Fail
assert(isequal(nextComb([1:17 22 24 27 30 35 36 38 44],50),[1:17 22 24 27 30 35 36 38 45]))

Error using zeros Maximum variable size allowed by the program is exceeded. Error in nchoosek>combs (line 164) P = zeros(total, k, 'like', v); Error in nchoosek (line 123) c = combs(v,k); Error in nextComb (line 2) comb = nchoosek(1:n,length(vec)); Error in Test17 (line 1) assert(isequal(nextComb([1:17 22 24 27 30 35 36 38 44],50),[1:17 22 24 27 30 35 36 38 45]))

18   Fail
assert(isequal(nextComb([1:16 18 19 22 23 27 44 45 46 48],50),[1:16 18 19 22 23 27 44 45 46 49]))

Error using zeros Maximum variable size allowed by the program is exceeded. Error in nchoosek>combs (line 164) P = zeros(total, k, 'like', v); Error in nchoosek (line 123) c = combs(v,k); Error in nextComb (line 2) comb = nchoosek(1:n,length(vec)); Error in Test18 (line 1) assert(isequal(nextComb([1:16 18 19 22 23 27 44 45 46 48],50),[1:16 18 19 22 23 27 44 45 46 49]))

19   Fail
assert(isequal(nextComb([1:13 15 23 25 26 28 30 32 38 39 42 46 50],50),[1:13 15 23 25 26 28 30 32 38 39 42 47 48]))

Error using zeros Maximum variable size allowed by the program is exceeded. Error in nchoosek>combs (line 164) P = zeros(total, k, 'like', v); Error in nchoosek (line 123) c = combs(v,k); Error in nextComb (line 2) comb = nchoosek(1:n,length(vec)); Error in Test19 (line 1) assert(isequal(nextComb([1:13 15 23 25 26 28 30 32 38 39 42 46 50],50),[1:13 15 23 25 26 28 30 32 38 39 42 47 48]))

20   Pass
assert(isequal(nextComb(1,9),2))

21   Pass
assert(isequal(nextComb(2,9),3))

22   Pass
assert(isequal(nextComb(3,9),4))

23   Pass
assert(isequal(nextComb(4,9),5))

24   Pass
assert(isequal(nextComb(5,9),6))

25   Pass
assert(isequal(nextComb(6,9),7))

26   Pass
assert(isequal(nextComb(7,9),8))

27   Pass
assert(isequal(nextComb(8,9),9))

28   Fail
assert(isequal(nextComb(9,9),9))

Index in position 1 exceeds array bounds (must not exceed 9). Error in nextComb (line 5) y = comb(idx+1,:); Error in Test28 (line 1) assert(isequal(nextComb(9,9),9))