Cody

Problem 753. Solitaire Cipher

Solution 2883401

Submitted on 27 Aug 2020 by carlos fuentes
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:28; n = 10; out = [3 22 9 4 23 7 25 16 14 14]; assert(isequal(solitaire(deck, n),out))

P = 27 V = 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 26 28 27 P = 27 V = 1 28 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 P1 = 28 P2 = 2 V = 28 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 1 P = 1 V = 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 1 P = 26 V = 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 28 27 1 P = 26 V = 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 1 28 P1 = 26 P2 = 28 V = 27 1 28 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 P = 26 V = 25 27 1 28 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 26 P = 2 V = 25 1 27 28 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 26 P = 4 V = 25 1 27 2 3 28 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 26 P1 = 3 P2 = 6 V = 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 26 27 2 3 28 25 1 P = 1 V = 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 26 27 2 3 28 25 4 1 P = 22 V = 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 26 2 27 3 28 25 4 1 P = 25 V = 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 26 2 27 3 25 4 28 1 P1 = 23 P2 = 27 V = 1 27 3 25 4 28 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 26 2 P = 2 V = 3 25 4 28 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 26 1 27 2 P = 27 V = 3 25 4 28 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 26 1 2 27 P = 4 V = 3 25 4 5 6 28 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 26 1 2 27 P1 = 28 P2 = 6 V = 28 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 26 1 2 27 3 25 4 5 6 P = 6 V = 12 13 14 15 16 17 18 19 20 21 22 23 24 26 1 2 27 3 25 4 5 28 7 8 9 10 11 6 P = 17 V = 12 13 14 15 16 17 18 19 20 21 22 23 24 26 1 2 3 27 25 4 5 28 7 8 9 10 11 6 P = 22 V = 12 13 14 15 16 17 18 19 20 21 22 23 24 26 1 2 3 27 25 4 5 7 8 28 9 10 11 6 P1 = 18 P2 = 24 V = 9 10 11 6 27 25 4 5 7 8 28 12 13 14 15 16 17 18 19 20 21 22 23 24 26 1 2 3 P = 3 V = 6 27 25 4 5 7 8 28 12 13 14 15 16 17 18 19 20 21 22 23 24 26 1 2 9 10 11 3 P = 2 V = 6 25 27 4 5 7 8 28 12 13 14 15 16 17 18 19 20 21 22 23 24 26 1 2 9 10 11 3 P = 8 V = 6 25 27 4 5 7 8 12 13 28 14 15 16 17 18 19 20 21 22 23 24 26 1 2 9 10 11 3 P1 = 3 P2 = 10 V = 14 15 16 17 18 19 20 21 22 23 24 26 1 2 9 10 11 3 27 4 5 7 8 12 13 28 6 25 P = 25 V = 28 6 14 15 16 17 18 19 20 21 22 23 24 26 1 2 9 10 11 3 27 4 5 7 8 12 13 25 P = 21 V = 28 6 14 15 16 17 18 19 20 21 22 23 24 26 1 2 9 10 11 3 4 27 5 7 8 12 13 25 P = 1 V = 6 14 28 15 16 17 18 19 20 21 22 23 24 26 1 2 9 10 11 3 4 27 5 7 8 12 13 25 P1 = 22 P2 = 3 V = 5 7 8 12 13 25 28 15 16 17 18 19 20 21 22 23 24 26 1 2 9 10 11 3 4 27 6 14 P = 14 V = 22 23 24 26 1 2 9 10 11 3 4 27 6 5 7 8 12 13 25 28 15 16 17 18 19 20 21 14 P = 12 V = 22 23 24 26 1 2 9 10 11 3 4 6 27 5 7 8 12 13 25 28 15 16 17 18 19 20 21 14 P = 20 V = 22 23 24 26 1 2 9 10 11 3 4 6 27 5 7 8 12 13 25 15 16 28 17 18 19 20 21 14 P1 = 13 P2 = 22 V = 17 18 19 20 21 14 27 5 7 8 12 13 25 15 16 28 22 23 24 26 1 2 9 10 11 3 4 6 P = 6 V = 27 5 7 8 12 13 25 15 16 28 22 23 24 26 1 2 9 10 11 3 4 17 18 19 20 21 14 6 P = 1 V = 5 27 7 8 12 13 25 15 16 28 22 23 24 26 1 2 9 10 11 3 4 17 18 19 20 21 14 6 P = 10 V = 5 27 7 8 12 13 25 15 16 22 23 28 24 26 1 2 9 10 11 3 4 17 18 19 20 21 14 6 P1 = 2 P2 = 12 V = 24 26 1 2 9 10 11 3 4 17 18 19 20 21 14 6 27 7 8 12 13 25 15 16 22 23 28 5 P = 5 V = 10 11 3 4 17 18 19 20 21 14 6 27 7 8 12 13 25 15 16 22 23 28 24 26 1 2 9 5

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

P = 27 V = 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 26 28 27 P = 27 V = 1 28 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 P1 = 28 P2 = 2 V = 28 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 1 P = 1 V = 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 1 P = 26 V = 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 28 27 1 P = 26 V = 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 1 28 P1 = 26 P2 = 28 V = 27 1 28 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 P = 26 V = 25 27 1 28 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 26 P = 2 V = 25 1 27 28 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 26 P = 4 V = 25 1 27 2 3 28 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 26 P1 = 3 P2 = 6 V = 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 26 27 2 3 28 25 1 P = 1 V = 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 26 27 2 3 28 25 4 1 P = 22 V = 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 26 2 27 3 28 25 4 1 P = 25 V = 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 26 2 27 3 25 4 28 1 P1 = 23 P2 = 27 V = 1 27 3 25 4 28 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 26 2 P = 2 V = 3 25 4 28 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 26 1 27 2 P = 27 V = 3 25 4 28 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 26 1 2 27 P = 4 V = 3 25 4 5 6 28 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 26 1 2 27 P1 = 28 P2 = 6 V = 28 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 26 1 2 27 3 25 4 5 6 P = 6 V = 12 13 14 15 16 17 18 19 20 21 22 23 24 26 1 2 27 3 25 4 5 28 7 8 9 10 11 6 P = 17 V = 12 13 14 15 16 17 18 19 20 21 22 23 24 26 1 2 3 27 25 4 5 28 7 8 9 10 11 6 P = 22 V = 12 13 14 15 16 17 18 19 20 21 22 23 24 26 1 2 3 27 25 4 5 7 8 28 9 10 11 6 P1 = 18 P2 = 24 V = 9 10 11 6 27 25 4 5 7 8 28 12 13 14 15 16 17 18 19 20 21 22 23 24 26 1 2 3 P = 3 V = 6 27 25 4 5 7 8 28 12 13 14 15 16 17 18 19 20 21 22 23 24 26 1 2 9 10 11 3 P = 2 V = 6 25 27 4 5 7 8 28 12 13 14 15 16 17 18 19 20 21 22 23 24 26 1 2 9 10 11 3 P = 8 V = 6 25 27 4 5 7 8 12 13 28 14 15 16 17 18 19 20 21 22 23 24 26 1 2 9 10 11 3 P1 = 3 P2 = 10 V = 14 15 16 17 18 19 20 21 22 23 24 26 1 2 9 10 11 3 27 4 5 7 8 12 13 28 6 25 P = 25 V = 28 6 14 15 16 17 18 19 20 21 22 23 24 26 1 2 9 10 11 3 27 4 5 7 8 12 13 25 P = 21 V = 28 6 14 15 16 17 18 19 20 21 22 23 24 26 1 2 9 10 11 3 4 27 5 7 8 12 13 25 P = 1 V = 6 14 28 15 16 17 18 19 20 21 22 23 24 26 1 2 9 10 11 3 4 27 5 7 8 12 13 25 P1 = 22 P2 = 3 V = 5 7 8 12 13 25 28 15 16 17 18 19 20 21 22 23 24 26 1 2 9 10 11 3 4 27 6 14 P = 14 V = 22 23 24 26 1 2 9 10 11 3 4 27 6 5 7 8 12 13 25 28 15 16 17 18 19 20 21 14 P = 12 V = 22 23 24 26 1 2 9 10 11 3 4 6 27 5 7 8 12 13 25 28 15 16 17 18 19 20 21 14 P = 20 V = 22 23 24 26 1 2 9 10 11 3 4 6 27 5 7 8 12 13 25 15 16 28 17 18 19 20 21 14 P1 = 13 P2 = 22 V = 17 18 19 20 21 14 27 5 7 8 12 13 25 15 16 28 22 23 24 26 1 2 9 10 11 3 4 6 P = 6 V = 27 5 7 8 12 13 25 15 16 28 22 23 24 26 1 2 9 10 11 3 4 17 18 19 20 21 14 6

Suggested Problems

More from this Author52

Community Treasure Hunt

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

Start Hunting!