Cody

Solution 439723

Submitted on 7 May 2014 by Axel
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
deck = [1 4 7 10 13 16 19 22 25 28 3 6 9 12 15 18 21 24 27 2 5 8 11 14 17 20 23 26]; n = 10; out = [8 26 1 4 7 23 8 8 4 24]; assert(isequal(solitaire(deck, n),out))

i = 19 j = 19 d = Columns 1 through 16 1 4 7 10 13 16 19 22 25 28 3 6 9 12 15 18 Columns 17 through 28 21 24 2 27 5 8 11 14 17 20 23 26 i = 10 j = 10 d = Columns 1 through 16 1 4 7 10 13 16 19 22 25 3 28 6 9 12 15 18 Columns 17 through 28 21 24 2 27 5 8 11 14 17 20 23 26 i = 11 j = 11 d = Columns 1 through 16 1 4 7 10 13 16 19 22 25 3 6 28 9 12 15 18 Columns 17 through 28 21 24 2 27 5 8 11 14 17 20 23 26 o = 8 i = 11 j = 11 d = Columns 1 through 16 23 26 28 9 12 15 18 21 24 2 1 27 4 7 10 13 Columns 17 through 28 16 19 22 25 3 5 8 11 14 17 20 6 i = 3 j = 3 d = Columns 1 through 16 23 26 9 28 12 15 18 21 24 2 1 27 4 7 10 13 Columns 17 through 28 16 19 22 25 3 5 8 11 14 17 20 6 i = 4 j = 4 d = Columns 1 through 16 23 26 9 12 28 15 18 21 24 2 1 27 4 7 10 13 Columns 17 through 28 16 19 22 25 3 5 8 11 14 17 20 6 o = 8 26 i = 12 j = 12 d = Columns 1 through 16 14 17 20 6 28 15 18 21 24 2 1 23 27 26 9 4 Columns 17 through 28 7 10 13 16 19 22 25 3 5 8 11 12 i = 5 j = 5 d = Columns 1 through 16 14 17 20 6 15 28 18 21 24 2 1 23 27 26 9 4 Columns 17 through 28 7 10 13 16 19 22 25 3 5 8 11 12 i = 6 j = 6 d = Columns 1 through 16 14 17 20 6 15 18 28 21 24 2 1 23 27 26 9 4 Columns 17 through 28 7 10 13 16 19 22 25 3 5 8 11 12 o = 8 26 1 i = 4 j = 4 d = Columns 1 through 16 2 1 23 14 27 17 20 6 15 26 9 4 7 10 13 16 Columns 17 through 28 19 22 25 3 5 8 11 12 28 21 24 18 i = 25 j = 25 d = Columns 1 through 16 2 1 23 14 27 17 20 6 15 26 9 4 7 10 13 16 Columns 17 through 28 19 22 25 3 5 8 11 12 21 28 24 18 i = 26 j = 26 d = Columns 1 through 16 2 1 23 14 27 17 20 6 15 26 9 4 7 10 13 16 Columns 17 through 28 19 22 25 3 5 8 11 12 21 24 28 18 o = 8 26 1 4 i = 15 j = 15 d = Columns 1 through 16 22 25 3 5 8 11 12 21 24 28 2 1 23 18 17 27 Columns 17 through 28 20 6 15 26 9 4 7 10 13 16 19 14 i = 10 j = 10 d = Columns 1 through 16 22 25 3 5 8 11 12 21 24 2 28 1 23 18 17 27 Columns 17 through 28 20 6 15 26 9 4 7 10 13 16 19 14 i = 11 j = 11 d = Columns 1 through 16 22 25 3 5 8 11 12 21 24 2 1 28 23 18 17 27 Columns 17 through 28 20 6 15 26 9 4 7 10 13 16 19 14 o = 8 26 1 4 7 i = 16 j = 16 d = Columns 1 through 16 6 15 26 9 4 7 10 13 16 19 14 28 23 18 17 22 Columns 17 through 28 27 25 3 5 8 11 12 21 24 2 20 1 i = 12 j = 12 d = Columns 1 through 16 6 15 26 9 4 7 10 13 16 19 14 23 28 18 17 22 Columns 17 through 28 27 25 3 5 8 11 12 21 24 2 20 1 i = 13 j = 13 d = Columns 1 through 16 6 15 26 9 4 7 10 13 16 19 14 23 18 28 17 22 Columns 17 through 28 27 25 3 5 8 11 12 21 24 2 20 1 o = 8 26 1 4 7 23 i = 24 j = 24 d = Columns 1 through 16 9 4 7 10 13 16 19 14 23 25 3 5 8 11 12 21 Columns 17 through 28 24 2 20 1 28 17 22 6 27 15 26 18 i = 21 j = 21 d = Columns 1 through 16 9 4 7 10 13 16 19 14 23 25 3 5 8 11 12 21 Columns 17 through 28 24 2 20 1 17 28 22 6 27 15 26 18 i = 22 j = 22 d = Columns 1 through 16 9 4 7 10 13 16 19 14 23 25 3 5 8 11 12 21 Columns 17 through 28 24 2 20 1 17 22 28 6 27 15 26 18 o = 8 26 1 4 7 23 8 i = 11 j = 11 d = Columns 1 through 16 24 2 20 1 17 15 26 18 28 6 9 27 4 7 10 13 Columns 17 through 28 16 19 14 23 25 3 5 8 11 12 21 22 i = 9 j = 9 d = Columns 1 through 16 24 2 20 1 17 15 26 18 6 28 9 27 4 7 10 13 Columns 17 through 28 16 19 14 23 25 3 5 8 11 12 21 22 i = 10 j = 10 d = Columns 1 through 16 24 2 20 1 17 15 26 18 6 9 28 27 4 7 10 13 Columns 17 through 28 16 19 14 23 25 3 5 8 11 12 21 22 o = 8 26 1 4 7 23 8 8 i = 9 j = 9 d = Columns 1 through 16 3 5 8 11 12 21 22 28 24 27 2 20 1 17 15 26 Columns 17 through 28 18 6 4 7 10 13 16 19 14 23 25 9 i = 8 j = 8 d = Columns 1 through 16 3 5 8 11 12 21 22 24 28 27 2 20 1 17 15 26 Columns 17 through 28 18 6 4 7 10 13 16 19 14 23 25 9 i = 9 j = 9 d = Columns 1 through 16 3 5 8 11 12 21 22 24 27 28 2 20 1 17 15 26 Columns 17 through 28 18 6 4 7 10 13 16 19 14 23 25 9 o = 8 26 1 4 7 23 8 8 4 i = 22 j = 22 d = Columns 1 through 16 12 21 22 2 20 1 17 15 26 18 6 4 7 10 13 16 Columns 17 through 28 19 14 23 25 9 28 27 3 5 8 11 24 i = 22 j = 22 d = Columns 1 through 16 12 21 22 2 20 1 17 15 26 18 6 4 7 10 13 16 Columns 17 through 28 19 14 23 25 9 27 28 3 5 8 11 24 i = 23 j = 23 d = Columns 1 through 16 12 21 22 2 20 1 17 15 26 18 6 4 7 10 13 16 Columns 17 through 28 19 14 23 25 9 27 3 28 5 8 11 24 o = 8 26 1 4 7 23 8 8 4 24

2   Pass
%% deck = 1:28; n = 10; out = [3 22 9 4 23 7 25 16 14 14]; assert(isequal(solitaire(deck, n),out))

i = 27 j = 27 d = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Columns 17 through 28 17 18 19 20 21 22 23 24 25 26 28 27 i = 27 j = 27 d = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Columns 17 through 28 17 18 19 20 21 22 23 24 25 26 27 28 i = 28 j = 0 d = Columns 1 through 16 1 28 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Columns 17 through 29 16 17 18 19 20 21 22 23 24 25 26 27 28 o = 3 i = 26 j = 26 d = Columns 1 through 16 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Columns 17 through 28 18 19 20 21 22 23 24 25 26 28 27 1 i = 26 j = 26 d = Columns 1 through 16 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Columns 17 through 28 18 19 20 21 22 23 24 25 26 27 28 1 i = 27 j = 27 d = Columns 1 through 16 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Columns 17 through 28 18 19 20 21 22 23 24 25 26 27 1 28 o = 3 22 i = 2 j = 2 d = Columns 1 through 16 25 1 27 28 2 3 4 5 6 7 8 9 10 11 12 13 Columns 17 through 28 14 15 16 17 18 19 20 21 22 23 24 26 i = 4 j = 4 d = Columns 1 through 16 25 1 27 2 28 3 4 5 6 7 8 9 10 11 12 13 Columns 17 through 28 14 15 16 17 18 19 20 21 22 23 24 26 i = 5 j = 5 d = Columns 1 through 16 25 1 27 2 3 28 4 5 6 7 8 9 10 11 12 13 Columns 17 through 28 14 15 16 17 18 19 20 21 22 23 24 26 o = 3 22 9 i = 22 j = 22 d = Columns 1 through 16 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Columns 17 through 28 21 22 23 24 26 2 27 3 28 25 4 1 i = 25 j = 25 d = Columns 1 through 16 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Columns 17 through 28 21 22 23 24 26 2 27 3 25 28 4 1 i = 26 j = 26 d = Columns 1 through 16 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Columns 17 through 28 21 22 23 24 26 2 27 3 25 4 28 1 o = 3 22 9 4 i = 27 j = 27 d = Columns 1 through 16 3 25 4 28 5 6 7 8 9 10 11 12 13 14 15 16 Columns 17 through 28 17 18 19 20 21 22 23 24 26 1 2 27 i = 4 j = 4 d = Columns 1 through 16 3 25 4 5 28 6 7 8 9 10 11 12 13 14 15 16 Columns 17 through 28 17 18 19 20 21 22 23 24 26 1 2 27 i = 5 j = 5 d = Columns 1 through 16 3 25 4 5 6 28 7 8 9 10 11 12 13 14 15 16 Columns 17 through 28 17 18 19 20 21 22 23 24 26 1 2 27 o = 3 22 9 4 23 i = 17 j = 17 d = Columns 1 through 16 12 13 14 15 16 17 18 19 20 21 22 23 24 26 1 2 Columns 17 through 28 3 27 25 4 5 28 7 8 9 10 11 6 i = 22 j = 22 d = Columns 1 through 16 12 13 14 15 16 17 18 19 20 21 22 23 24 26 1 2 Columns 17 through 28 3 27 25 4 5 7 28 8 9 10 11 6 i = 23 j = 23 d = Columns 1 through 16 12 13 14 15 16 17 18 19 20 21 22 23 24 26 1 2 Columns 17 through 28 3 27 25 4 5 7 8 28 9 10 11 6 o = 3 22 9 4 23 7 i = 2 j = 2 d = Columns 1 through 16 6 25 27 4 5 7 8 28 12 13 14 15 16 17 18 19 Columns 17 through 28 20 21 22 23 24 26 1 2 9 10 11 3 i = 8 j = 8 d = Columns 1 through 16 6 25 27 4 5 7 8 12 28 13 14 15 16 17 18 19 Columns 17 through 28 20 21 22 23 24 26 1 2 9 10 11 3 i = 9 j = 9 d = Columns 1 through 16 6 25 27 4 5 7 8 12 13 28 14 15 16 17 18 19 Columns 17 through 28 20 21 22 23 24 26 1 2 9 10 11 3 o = 3 22 9 4 23 7 25 i = 21 j = 21 d = Columns 1 through 16 28 6 14 15 16 17 18 19 20 21 22 23 24 26 1 2 Columns 17 through 28 9 10 11 3 4 27 5 7 8 12 13 25 i = 1 j = 1 d = Columns 1 through 16 6 28 14 15 16 17 18 19 20 21 22 23 24 26 1 2 Columns 17 through 28 9 10 11 3 4 27 5 7 8 12 13 25 i = 2 j = 2 d = Columns 1 through 16 6 14 28 15 16 17 18 19 20 21 22 23 24 26 1 2 Columns 17 through 28 9 10 11 3 4 27 5 7 8 12 13 25 o = 3 22 9 4 23 7 25 16 i = 12 j = 12 d = Columns 1 through 16 22 23 24 26 1 2 9 10 11 3 4 6 27 5 7 8 Columns 17 through 28 12 13 25 28 15 16 17 18 19 20 21 14 i = 20 j = 20 d = Columns 1 through 16 22 23 24 26 1 2 9 10 11 3 4 6 27 5 7 8 Columns 17 through 28 12 13 25 15 28 16 17 18 19 20 21 14 i = 21 j = 21 d = Columns 1 through 16 22 23 24 26 1 2 9 10 11 3 4 6 27 5 7 8 Columns 17 through 28 12 13 25 15 16 28 17 18 19 20 21 14 o = 3 22 9 4 23 7 25 16 14 i = 1 j = 1 d = Columns 1 through 16 5 27 7 8 12 13 25 15 16 28 22 23 24 26 1 2 Columns 17 through 28 9 10 11 3 4 17 18 19 20 21 14 6 i = 10 j = 10 d = Columns 1 through 16 5 27 7 8 12 13 25 15 16 22 28 23 24 26 1 2 Columns 17 through 28 9 10 11 3 4 17 18 19 20 21 14 6 i = 11 j = 11 d = Columns 1 through 16 5 27 7 8 12 13 25 15 16 22 23 28 24 26 1 2 Columns 17 through 28 9 10 11 3 4 17 18 19 20 21 14 6 o = 3 22 9 4 23 7 25 16 14 14

3   Pass
%% deck = 1:28; n = 9; out = [3 22 9 4 23 7 25 16 14]; assert(isequal(solitaire(deck, n),out))

i = 27 j = 27 d = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Columns 17 through 28 17 18 19 20 21 22 23 24 25 26 28 27 i = 27 j = 27 d = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Columns 17 through 28 17 18 19 20 21 22 23 24 25 26 27 28 i = 28 j = 0 d = Columns 1 through 16 1 28 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Columns 17 through 29 16 17 18 19 20 21 22 23 24 25 26 27 28 o = 3 i = 26 j = 26 d = Columns 1 through 16 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Columns 17 through 28 18 19 20 21 22 23 24 25 26 28 27 1 i = 26 j = 26 d = Columns 1 through 16 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Columns 17 through 28 18 19 20 21 22 23 24 25 26 27 28 1 i = 27 j = 27 d = Columns 1 through 16 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Columns 17 through 28 18 19 20 21 22 23 24 25 26 27 1 28 o = 3 22 i = 2 j = 2 d = Columns 1 through 16 25 1 27 28 2 3 4 5 6 7 8 9 10 11 12 13 Columns 17 through 28 14 15 16 17 18 19 20 21 22 23 24 26 i = 4 j = 4 d = Columns 1 through 16 25 1 27 2 28 3 4 5 6 7 8 9 10 11 12 13 Columns 17 through 28 14 15 16 17 18 19 20 21 22 23 24 26 i = 5 j = 5 d = Columns 1 through 16 25 1 27 2 3 28 4 5 6 7 8 9 10 11 12 13 Columns 17 through 28 14 15 16 17 18 19 20 21 22 23 24 26 o = 3 22 9 i = 22 j = 22 d = Columns 1 through 16 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Columns 17 through 28 21 22 23 24 26 2 27 3 28 25 4 1 i = 25 j = 25 d = Columns 1 through 16 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Columns 17 through 28 21 22 23 24 26 2 27 3 25 28 4 1 i = 26 j = 26 d = Columns 1 through 16 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Columns 17 through 28 21 22 23 24 26 2 27 3 25 4 28 1 o = 3 22 9 4 i = 27 j = 27 d = Columns 1 through 16 3 25 4 28 5 6 7 8 9 10 11 12 13 14 15 16 Columns 17 through 28 17 18 19 20 21 22 23 24 26 1 2 27 i = 4 j = 4 d = Columns 1 through 16 3 25 4 5 28 6 7 8 9 10 11 12 13 14 15 16 Columns 17 through 28 17 18 19 20 21 22 23 24 26 1 2 27 i = 5 j = 5 d = Columns 1 through 16 3 25 4 5 6 28 7 8 9 10 11 12 13 14 15 16 Columns 17 through 28 17 18 19 20 21 22 23 24 26 1 2 27 o = 3 22 9 4 23 i = 17 j = 17 d = Columns 1 through 16 12 13 14 15 16 17 18 19 20 21 22 23 24 26 1 2 Columns 17 through 28 3 27 25 4 5 28 7 8 9 10 11 6 i = 22 j = 22 d = Columns 1 through 16 12 13 14 15 16 17 18 19 20 21 22 23 24 26 1 2 Columns 17 through 28 3 27 25 4 5 7 28 8 9 10 11 6 i = 23 j = 23 d = Columns 1 through 16 12 13 14 15 16 17 18 19 20 21 22 23 24 26 1 2 Columns 17 through 28 3 27 25 4 5 7 8 28 9 10 11 6 o = 3 22 9 4 23 7 i = 2 j = 2 d = Columns 1 through 16 6 25 27 4 5 7 8 28 12 13 14 15 16 17 18 19 Columns 17 through 28 20 21 22 23 24 26 1 2 9 10 11 3 i = 8 j = 8 d = Columns 1 through 16 6 25 27 4 5 7 8 12 28 13 14 15 16 17 18 19 Columns 17 through 28 20 21 22 23 24 26 1 2 9 10 11 3 i = 9 j = 9 d = Columns 1 through 16 6 25 27 4 5 7 8 12 13 28 14 15 16 17 18 19 Columns 17 through 28 20 21 22 23 24 26 1 2 9 10 11 3 o = 3 22 9 4 23 7 25 i = 21 j = 21 d = Columns 1 through 16 28 6 14 15 16 17 18 19 20 21 22 23 24 26 1 2 Columns 17 through 28 9 10 11 3 4 27 5 7 8 12 13 25 i = 1 j = 1 d = Columns 1 through 16 6 28 14 15 16 17 18 19 20 21 22 23 24 26 1 2 Columns 17 through 28 9 10 11 3 4 27 5 7 8 12 13 25 i = 2 j = 2 d = Columns 1 through 16 6 14 28 15 16 17 18 19 20 21 22 23 24 26 1 2 Columns 17 through 28 9 10 11 3 4 27 5 7 8 12 13 25 o = 3 22 9 4 23 7 25 16 i = 12 j = 12 d = Columns 1 through 16 22 23 24 26 1 2 9 10 11 3 4 6 27 5 7 8 Columns 17 through 28 12 13 25 28 15 16 17 18 19 20 21 14 i = 20 j = 20 d = Columns 1 through 16 22 23 24 26 1 2 9 10 11 3 4 6 27 5 7 8 Columns 17 through 28 12 13 25 15 28 16 17 18 19 20 21 14 i = 21 j = 21 d = Columns 1 through 16 22 23 24 26 1 2 9 10 11 3 4 6 27 5 7 8 Columns 17 through 28 12 13 25 15 16 28 17 18 19 20 21 14 o = 3 22 9 4 23 7 25 16 14

Suggested Problems

More from this Author52