Cody

# Problem 766. Implement Solitaire cipher for N long deck.

Solution 127661

Submitted on 14 Aug 2012 by @bmtran (Bryant Tran)
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]; m = 10; out = [8 26 1 4 7 23 8 8 4 24]; assert(isequal(solitaire(deck, m),out))

deck = Columns 1 through 10 1 4 7 10 13 16 19 22 25 28 Columns 11 through 20 3 6 9 12 15 18 21 24 2 27 Columns 21 through 28 5 8 11 14 17 20 23 26 j2 = 10 deck = Columns 1 through 10 1 4 7 10 13 16 19 22 25 3 Columns 11 through 20 6 28 9 12 15 18 21 24 2 27 Columns 21 through 28 5 8 11 14 17 20 23 26 deck = Columns 1 through 10 5 8 11 14 17 20 23 26 28 9 Columns 11 through 20 12 15 18 21 24 2 27 1 4 7 Columns 21 through 28 10 13 16 19 22 25 3 6 deck = Columns 1 through 10 23 26 28 9 12 15 18 21 24 2 Columns 11 through 20 27 1 4 7 10 13 16 19 22 25 Columns 21 through 28 3 5 8 11 14 17 20 6 out = 8 0 0 0 0 0 0 0 0 0 deck = Columns 1 through 10 23 26 28 9 12 15 18 21 24 2 Columns 11 through 20 1 27 4 7 10 13 16 19 22 25 Columns 21 through 28 3 5 8 11 14 17 20 6 j2 = 3 deck = Columns 1 through 10 23 26 9 12 28 15 18 21 24 2 Columns 11 through 20 1 27 4 7 10 13 16 19 22 25 Columns 21 through 28 3 5 8 11 14 17 20 6 deck = Columns 1 through 10 4 7 10 13 16 19 22 25 3 5 Columns 11 through 20 8 11 14 17 20 6 28 15 18 21 Columns 21 through 28 24 2 1 27 23 26 9 12 deck = Columns 1 through 10 14 17 20 6 28 15 18 21 24 2 Columns 11 through 20 1 27 23 26 9 4 7 10 13 16 Columns 21 through 28 19 22 25 3 5 8 11 12 out = 8 26 0 0 0 0 0 0 0 0 deck = Columns 1 through 10 14 17 20 6 28 15 18 21 24 2 Columns 11 through 20 1 23 27 26 9 4 7 10 13 16 Columns 21 through 28 19 22 25 3 5 8 11 12 j2 = 5 deck = Columns 1 through 10 14 17 20 6 15 18 28 21 24 2 Columns 11 through 20 1 23 27 26 9 4 7 10 13 16 Columns 21 through 28 19 22 25 3 5 8 11 12 deck = Columns 1 through 10 26 9 4 7 10 13 16 19 22 25 Columns 11 through 20 3 5 8 11 12 28 21 24 2 1 Columns 21 through 28 23 27 14 17 20 6 15 18 deck = Columns 1 through 10 2 1 23 27 14 17 20 6 15 26 Columns 11 through 20 9 4 7 10 13 16 19 22 25 3 Columns 21 through 28 5 8 11 12 28 21 24 18 out = 8 26 1 0 0 0 0 0 0 0 deck = Columns 1 through 10 2 1 23 14 27 17 20 6 15 26 Columns 11 through 20 9 4 7 10 13 16 19 22 25 3 Columns 21 through 28 5 8 11 12 28 21 24 18 j2 = 25 deck = Columns 1 through 10 2 1 23 14 27 17 20 6 15 26 Columns 11 through 20 9 4 7 10 13 16 19 22 25 3 Columns 21 through 28 5 8 11 12 21 24 28 18 deck = Columns 1 through 10 18 27 17 20 6 15 26 9 4 7 Columns 11 through 20 10 13 16 19 22 25 3 5 8 11 Columns 21 through 28 12 21 24 28 2 1 23 14 deck = Columns 1 through 10 22 25 3 5 8 11 12 21 24 28 Columns 11 through 20 2 1 23 18 27 17 20 6 15 26 Columns 21 through 28 9 4 7 10 13 16 19 14 out = 8 26 1 4 0 0 0 0 0 0 deck = Columns 1 through 10 22 25 3 5 8 11 12 21 24 28 Columns 11 through 20 2 1 23 18 17 27 20 6 15 26 Columns 21 through 28 9 4 7 10 13 16 19 14 j2 = 10 deck = Columns 1 through 10 22 25 3 5 8 11 12 21 24 2 Columns 11 through 20 1 28 23 18 17 27 20 6 15 26 Columns 21 through 28 9 4 7 10 13 16 19 14 deck = Columns 1 through 10 20 6 15 26 9 4 7 10 13 16 Columns 11 through 20 19 14 28 23 18 17 27 22 25 3 Columns 21 through 28 5 8 11 12 21 24 2 1 deck = Columns 1 through 10 6 15 26 9 4 7 10 13 16 19 Columns 11 through 20 14 28 23 18 17 27 22 25 3 5 Columns 21 through 28 8 11 12 21 24 2 20 1 out = 8 26 1 4 7 0 0 0 0 0 deck = Columns 1 through 10 6 15 26 9 4 7 10 13 16 19 Columns 11 through 20 14 28 23 18 17 22 27 25 3 5 Columns 21 through 28 8 11 12 21 24 2 20 1 j2 = 12 deck = Columns 1 through 10 6 15 26 9 4 7 10 13 16 19 Columns 11 through 20 14 23 18 28 17 22 27 25 3 5 Columns 21 through 28 8 11 12 21 24 2 20 1 deck = Columns 1 through 10 25 3 5 8 11 12 21 24 2 20 Columns 11 through 20 1 28 17 22 27 6 15 26 9 4 Columns 21 through 28 7 10 13 16 19 14 23 18 deck = Columns 1 through 10 9 4 7 10 13 16 19 14 23 25 Columns 11 through 20 3 5 8 11 12 21 24 2 20 1 Columns 21 through 28 28 17 22 27 6 15 26 18 out = 8 26 1 4 7 23 0 0 0 0 deck = Columns 1 through 10 9 4 7 10 13 16 19 14 23 25 Columns 11 through 20 3 5 8 11 12 21 24 2 20 1 Columns 21 through 28 28 17 22 6 27 15 26 18 j2 = 21 deck = Columns 1 through 10 9 4 7 10 13 16 19 14 23 25 Columns 11 through 20 3 5 8 11 12 21 24 2 20 1 Columns 21 through 28 17 22 28 6 27 15 26 18 deck = Columns 1 through 10 15 26 18 28 6 27 9 4 7 10 Columns 11 through 20 13 16 19 14 23 25 3 5 8 11 Columns 21 through 28 12 21 24 2 20 1 17 22 deck = Columns 1 through 10 24 2 20 1 17 15 26 18 28 6 Columns 11 through 20 27 9 4 7 10 13 16 19 14 23 Columns 21 through 28 25 3 5 8 11 12 21 22 out = 8 26 1 4 7 23 8 0 0 0 deck = Columns 1 through 10 24 2 20 1 17 15 26 18 28 6 Columns 11 through 20 9 27 4 7 10 13 16 19 14 23 Columns 21 through 28 25 3 5 8 11 12 21 22 j2 = 9 deck = Columns 1 through 10 24 2 20 1 17 15 26 18 6 9 Columns 11 through 20 28 27 4 7 10 13 16 19 14 23 Columns 21 through 28 25 3 5 8 11 12 21 22 deck = Columns 1 through 10 4 7 10 13 16 19 14 23 25 3 Columns 11 through 20 5 8 11 12 21 22 28 27 24 2 Columns 21 through 28 20 1 17 15 26 18 6 9 deck = Columns 1 through 10 3 5 8 11 12 21 22 28 27 24 Columns 11 through 20 2 20 1 17 15 26 18 6 4 7 Columns 21 through 28 10 13 16 19 14 23 25 9 out = 8 26 1 4 7 23 8 8 0 0 deck = Columns 1 through 10 3 5 8 11 12 21 22 28 24 27 Columns 11 through 20 2 20 1 17 15 26 18 6 4 7 Columns 21 through 28 10 13 16 19 14 23 25 9 j2 = 8 deck = Columns 1 through 10 3 5 8 11 12 21 22 24 27 28 Columns 11 through 20 2 20 1 17 15 26 18 6 4 7 Columns 21 through 28 10 13 16 19 14 23 25 9 deck = Columns 1 through 10 2 20 1 17 15 26 18 6 4 7 Columns 11 through 20 10 13 16 19 14 23 25 9 27 28 Columns 21 through 28 3 5 8 11 12 21 22 24 deck = Columns 1 through 10 12 21 22 2 20 1 17 15 26 18 Columns 11 through 20 6 4 7 10 13 16 19 14 23 25 Columns 21 through 28 9 27 28 3 5 8 11 24 out = 8 26 1 4 7 23 8 8 4 0 deck = Columns 1 through 10 12 21 22 2 20 1 17 15 26 18 Columns 11 through 20 6 4 7 10 13 16 19 14 23 25 Columns 21 through 28 9 28 27 3 5 8 11 24 j2 = 22 deck = Columns 1 through 10 12 21 22 2 20 ...

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

deck = Columns 1 through 10 1 2 3 4 5 6 7 8 9 10 Columns 11 through 20 11 12 13 14 15 16 17 18 19 20 Columns 21 through 28 21 22 23 24 25 26 28 27 j2 = 27 deck = Columns 1 through 10 1 28 2 3 4 5 6 7 8 9 Columns 11 through 20 10 11 12 13 14 15 16 17 18 19 Columns 21 through 28 20 21 22 23 24 25 26 27 deck = Columns 1 through 10 28 2 3 4 5 6 7 8 9 10 Columns 11 through 20 11 12 13 14 15 16 17 18 19 20 Columns 21 through 28 21 22 23 24 25 26 27 1 deck = Columns 1 through 10 2 3 4 5 6 7 8 9 10 11 Columns 11 through 20 12 13 14 15 16 17 18 19 20 21 Columns 21 through 28 22 23 24 25 26 27 28 1 out = 3 0 0 0 0 0 0 0 0 0 deck = Columns 1 through 10 2 3 4 5 6 7 8 9 10 11 Columns 11 through 20 12 13 14 15 16 17 18 19 20 21 Columns 21 through 28 22 23 24 25 26 28 27 1 j2 = 26 deck = Columns 1 through 10 2 3 4 5 6 7 8 9 10 11 Columns 11 through 20 12 13 14 15 16 17 18 19 20 21 Columns 21 through 28 22 23 24 25 26 27 1 28 deck = Columns 1 through 10 27 1 28 2 3 4 5 6 7 8 Columns 11 through 20 9 10 11 12 13 14 15 16 17 18 Columns 21 through 28 19 20 21 22 23 24 25 26 deck = Columns 1 through 10 25 27 1 28 2 3 4 5 6 7 Columns 11 through 20 8 9 10 11 12 13 14 15 16 17 Columns 21 through 28 18 19 20 21 22 23 24 26 out = 3 22 0 0 0 0 0 0 0 0 deck = Columns 1 through 10 25 1 27 28 2 3 4 5 6 7 Columns 11 through 20 8 9 10 11 12 13 14 15 16 17 Columns 21 through 28 18 19 20 21 22 23 24 26 j2 = 4 deck = Columns 1 through 10 25 1 27 2 3 28 4 5 6 7 Columns 11 through 20 8 9 10 11 12 13 14 15 16 17 Columns 21 through 28 18 19 20 21 22 23 24 26 deck = Columns 1 through 10 4 5 6 7 8 9 10 11 12 13 Columns 11 through 20 14 15 16 17 18 19 20 21 22 23 Columns 21 through 28 24 26 27 2 3 28 25 1 deck = Columns 1 through 10 5 6 7 8 9 10 11 12 13 14 Columns 11 through 20 15 16 17 18 19 20 21 22 23 24 Columns 21 through 28 26 27 2 3 28 25 4 1 out = 3 22 9 0 0 0 0 0 0 0 deck = Columns 1 through 10 5 6 7 8 9 10 11 12 13 14 Columns 11 through 20 15 16 17 18 19 20 21 22 23 24 Columns 21 through 28 26 2 27 3 28 25 4 1 j2 = 25 deck = Columns 1 through 10 5 6 7 8 9 10 11 12 13 14 Columns 11 through 20 15 16 17 18 19 20 21 22 23 24 Columns 21 through 28 26 2 27 3 25 4 28 1 deck = Columns 1 through 10 1 27 3 25 4 28 5 6 7 8 Columns 11 through 20 9 10 11 12 13 14 15 16 17 18 Columns 21 through 28 19 20 21 22 23 24 26 2 deck = Columns 1 through 10 3 25 4 28 5 6 7 8 9 10 Columns 11 through 20 11 12 13 14 15 16 17 18 19 20 Columns 21 through 28 21 22 23 24 26 1 27 2 out = 3 22 9 4 0 0 0 0 0 0 deck = Columns 1 through 10 3 25 4 28 5 6 7 8 9 10 Columns 11 through 20 11 12 13 14 15 16 17 18 19 20 Columns 21 through 28 21 22 23 24 26 1 2 27 j2 = 4 deck = Columns 1 through 10 3 25 4 5 6 28 7 8 9 10 Columns 11 through 20 11 12 13 14 15 16 17 18 19 20 Columns 21 through 28 21 22 23 24 26 1 2 27 deck = Columns 1 through 10 28 7 8 9 10 11 12 13 14 15 Columns 11 through 20 16 17 18 19 20 21 22 23 24 26 Columns 21 through 28 1 2 27 3 25 4 5 6 deck = Columns 1 through 10 12 13 14 15 16 17 18 19 20 21 Columns 11 through 20 22 23 24 26 1 2 27 3 25 4 Columns 21 through 28 5 28 7 8 9 10 11 6 out = 3 22 9 4 23 0 0 0 0 0 deck = Columns 1 through 10 12 13 14 15 16 17 18 19 20 21 Columns 11 through 20 22 23 24 26 1 2 3 27 25 4 Columns 21 through 28 5 28 7 8 9 10 11 6 j2 = 22 deck = Columns 1 through 10 12 13 14 15 16 17 18 19 20 21 Columns 11 through 20 22 23 24 26 1 2 3 27 25 4 Columns 21 through 28 5 7 8 28 9 10 11 6 deck = Columns 1 through 10 9 10 11 6 27 25 4 5 7 8 Columns 11 through 20 28 12 13 14 15 16 17 18 19 20 Columns 21 through 28 21 22 23 24 26 1 2 3 deck = Columns 1 through 10 6 27 25 4 5 7 8 28 12 13 Columns 11 through 20 14 15 16 17 18 19 20 21 22 23 Columns 21 through 28 24 26 1 2 9 10 11 3 out = 3 22 9 4 23 7 0 0 0 0 deck = Columns 1 through 10 6 25 27 4 5 7 8 28 12 13 Columns 11 through 20 14 15 16 17 18 19 20 21 22 23 Columns 21 through 28 24 26 1 2 9 10 11 3 j2 = 8 deck = Columns 1 through 10 6 25 27 4 5 7 8 12 13 28 Columns 11 through 20 14 15 16 17 18 19 20 21 22 23 Columns 21 through 28 24 26 1 2 9 10 11 3 deck = Columns 1 through 10 14 15 16 17 18 19 20 21 22 23 Columns 11 through 20 24 26 1 2 9 10 11 3 27 4 Columns 21 through 28 5 7 8 12 13 28 6 25 deck = Columns 1 through 10 28 6 14 15 16 17 18 19 20 21 Columns 11 through 20 22 23 24 26 1 2 9 10 11 3 Columns 21 through 28 27 4 5 7 8 12 13 25 out = 3 22 9 4 23 7 25 0 0 0 deck = Columns 1 through 10 28 6 14 15 16 17 18 19 20 21 Columns 11 through 20 22 23 24 26 1 2 9 10 11 3 Columns 21 through 28 4 27 5 7 8 12 13 25 j2 = 1 deck = Columns 1 through 10 6 14 28 15 16 17 18 19 20 21 Columns 11 through 20 22 23 24 26 1 2 9 10 11 3 Columns 21 through 28 4 27 5 7 8 12 13 25 deck = Columns 1 through 10 5 7 8 12 13 25 28 15 16 17 Columns 11 through 20 18 19 20 21 22 23 24 26 1 2 Columns 21 through 28 9 10 11 3 4 27 6 14 deck = Columns 1 through 10 22 23 24 26 1 2 9 10 11 3 Columns 11 through 20 4 27 6 5 7 8 12 13 25 28 Columns 21 through 28 15 16 17 18 19 20 21 14 out = 3 22 9 4 23 7 25 16 0 0 deck = Columns 1 through 10 22 23 24 26 1 2 9 10 11 3 Columns 11 through 20 4 6 27 5 7 8 12 13 25 28 Columns 21 through 28 15 16 17 18 19 20 21 14 j2 = 20 deck = Columns 1 through 10 22 23 24 26 1 2 9 10 11 3 Columns 11 through 20 4 6 27 5 7 8 12 13 25 15 Columns 21 through 28 16 28 17 18 19 20 21 14 deck = Columns 1 through 10 17 18 19 20 21 14 27 5 7 8 Columns 11 through 20 12 13 25 15 16 28 22 23 24 26 Columns 21 through 28 1 2 9 10 11 3 4 6 deck = Columns 1 through 10 27 5 7 8 12 13 25 15 16 28 Columns 11 through 20 22 23 24 26 1 2 9 10 11 3 Columns 21 through 28 4 17 18 19 20 21 14 6 out = 3 22 9 4 23 7 25 16 14 0 deck = Columns 1 through 10 5 27 7 8 12 13 25 15 16 28 Columns 11 through 20 22 23 24 26 1 2 9 10 11 3 Columns 21 through 28 4 17 18 19 20 21 14 6 j2 = 10 deck = Columns 1 through 10 5 27 7 8 12 ...

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

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

### Community Treasure Hunt

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

Start Hunting!