Cody

Solution 1940591

Submitted on 18 Sep 2019 by Augusto Mazzei
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
urlwrite('https://sites.google.com/a/alfnie.com/alfnie/software/SetSolutionScore.p?attredirects=0&d=1','SetSolutionScore.p'); rehash path;

2   Pass
x = 1:5; for spatula = sort_pancakes(x) x(1:spatula) = flip(x(1:spatula)); end assert(issorted(x))

st = 4 3 2 1 5 y = 4 4 st = 1 2 3 4 5 st = 3 2 1 4 5 y = 4 4 3 3 st = 1 2 3 4 5 st = 2 1 3 4 5 y = 4 4 3 3 2 2 st = 1 2 3 4 5

3   Pass
x = [6 4 2 5 3 1]; for spatula = sort_pancakes(x) x(1:spatula) = flip(x(1:spatula)); end assert(issorted(x))

y = 6 st = 1 3 5 2 4 6 st = 5 3 1 2 4 6 y = 6 3 5 st = 4 2 1 3 5 6 y = 6 3 5 4 st = 3 1 2 4 5 6 y = 6 3 5 4 3 st = 2 1 3 4 5 6 y = 6 3 5 4 3 2 st = 1 2 3 4 5 6

4   Pass
x = randperm(12); for spatula = sort_pancakes(x) x(1:spatula) = flip(x(1:spatula)); end assert(issorted(x))

st = 12 9 8 6 2 1 4 11 3 5 10 7 y = 4 12 st = 7 10 5 3 11 4 1 2 6 8 9 12 st = 11 3 5 10 7 4 1 2 6 8 9 12 y = 4 12 5 11 st = 9 8 6 2 1 4 7 10 5 3 11 12 st = 10 7 4 1 2 6 8 9 5 3 11 12 y = 4 12 5 11 8 10 st = 3 5 9 8 6 2 1 4 7 10 11 12 st = 9 5 3 8 6 2 1 4 7 10 11 12 y = 4 12 5 11 8 10 3 9 st = 7 4 1 2 6 8 3 5 9 10 11 12 st = 8 6 2 1 4 7 3 5 9 10 11 12 y = 4 12 5 11 8 10 3 9 6 8 st = 5 3 7 4 1 2 6 8 9 10 11 12 st = 7 3 5 4 1 2 6 8 9 10 11 12 y = 4 12 5 11 8 10 3 9 6 8 3 7 st = 6 2 1 4 5 3 7 8 9 10 11 12 y = 4 12 5 11 8 10 3 9 6 8 3 7 6 st = 3 5 4 1 2 6 7 8 9 10 11 12 st = 5 3 4 1 2 6 7 8 9 10 11 12 y = 4 12 5 11 8 10 3 9 6 8 3 7 6 2 5 st = 2 1 4 3 5 6 7 8 9 10 11 12 st = 4 1 2 3 5 6 7 8 9 10 11 12 y = 4 12 5 11 8 10 3 9 6 8 3 7 6 2 5 3 4 st = 3 2 1 4 5 6 7 8 9 10 11 12 y = 4 12 5 11 8 10 3 9 6 8 3 7 6 2 5 3 4 3 st = 1 2 3 4 5 6 7 8 9 10 11 12 st = 2 1 3 4 5 6 7 8 9 10 11 12 y = 4 12 5 11 8 10 3 9 6 8 3 7 6 2 5 3 4 3 2 2 st = 1 2 3 4 5 6 7 8 9 10 11 12

5   Pass
x = randperm(13); for spatula = sort_pancakes(x) x(1:spatula) = flip(x(1:spatula)); end assert(issorted(x))

st = 13 9 8 2 5 1 12 3 10 6 4 11 7 y = 12 13 st = 7 11 4 6 10 3 12 1 5 2 8 9 13 st = 12 3 10 6 4 11 7 1 5 2 8 9 13 y = 12 13 7 12 st = 9 8 2 5 1 7 11 4 6 10 3 12 13 st = 11 7 1 5 2 8 9 4 6 10 3 12 13 y = 12 13 7 12 7 11 st = 3 10 6 4 9 8 2 5 1 7 11 12 13 st = 10 3 6 4 9 8 2 5 1 7 11 12 13 y = 12 13 7 12 7 11 2 10 st = 7 1 5 2 8 9 4 6 3 10 11 12 13 st = 9 8 2 5 1 7 4 6 3 10 11 12 13 y = 12 13 7 12 7 11 2 10 6 9 st = 3 6 4 7 1 5 2 8 9 10 11 12 13 st = 8 2 5 1 7 4 6 3 9 10 11 12 13 y = 12 13 7 12 7 11 2 10 6 9 8 8 st = 3 6 4 7 1 5 2 8 9 10 11 12 13 st = 7 4 6 3 1 5 2 8 9 10 11 12 13 y = 12 13 7 12 7 11 2 10 6 9 8 8 4 7 st = 2 5 1 3 6 4 7 8 9 10 11 12 13 st = 6 3 1 5 2 4 7 8 9 10 11 12 13 y = 12 13 7 12 7 11 2 10 6 9 8 8 4 7 5 6 st = 4 2 5 1 3 6 7 8 9 10 11 12 13 st = 5 2 4 1 3 6 7 8 9 10 11 12 13 y = 12 13 7 12 7 11 2 10 6 9 8 8 4 7 5 6 3 5 st = 3 1 4 2 5 6 7 8 9 10 11 12 13 st = 4 1 3 2 5 6 7 8 9 10 11 12 13 y = 12 13 7 12 7 11 2 10 6 9 8 8 4 7 5 6 3 5 3 4 st = 2 3 1 4 5 6 7 8 9 10 11 12 13 st = 3 2 1 4 5 6 7 8 9 10 11 12 13 y = 12 13 7 12 7 11 2 10 6 9 8 8 4 7 5 6 3 5 3 4 2 3 st = 1 2 3 4 5 6 7 8 9 10 11 12 13 st = 2 1 3 4 5 6 7 8 9 10 11 12 13 y = 12 13 7 12 7 11 2 10 6 9 8 8 4 7 5 6 3 5 3 4 2 3 2 2 st = 1 2 3 4 5 6 7 8 9 10 11 12 13

6   Pass
for k = 1:20 x = randperm(k); for spatula = sort_pancakes(x) x(1:spatula) = flip(x(1:spatula)); end assert(issorted(x)) end

y = 3 st = 1 2 3 st = 2 1 3 y = 3 2 2 st = 1 2 3 st = 4 2 1 3 y = 2 4 st = 3 1 2 4 y = 2 4 3 st = 2 1 3 4 y = 2 4 3 2 st = 1 2 3 4 st = 5 2 4 1 3 y = 4 5 st = 3 1 4 2 5 st = 4 1 3 2 5 y = 4 5 3 4 st = 2 3 1 4 5 st = 3 2 1 4 5 y = 4 5 3 4 2 3 st = 1 2 3 4 5 st = 2 1 3 4 5 y = 4 5 3 4 2 3 2 2 st = 1 2 3 4 5 st = 6 5 1 4 3 2 y = 5 6 st = 2 3 4 1 5 6 st = 5 1 4 3 2 6 y = 5 6 5 5 st = 2 3 4 1 5 6 st = 4 3 2 1 5 6 y = 5 6 5 5 3 4 st = 1 2 3 4 5 6 st = 3 2 1 4 5 6 y = 5 6 5 5 3 4 3 3 st = 1 2 3 4 5 6 st = 2 1 3 4 5 6 y = 5 6 5 5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9 st = 2 1 3 4 5 6 7 8 9 y = 5 9 4 8 3 7 4 6 3 5 4 3 2 2 st = 1 2 3 4 5 6 7 8 9 st = 10 4 7 2 9 5 3 8 6 1 y = 3 10 st = 1 6 8 3 5 9 2 7 4 10 st = 9 5 3 8 6 1 2 7 4 10 y = 3 10 6 9 st = 4 7 2 1 6 8 3 5 9 10 st = 8 6 1 2 7 4 3 5 9 10 y = 3 10 6 9 6 8 st = 5 3 4 7 2 1 6 8 9 10 st = 7 4 3 5 2 1 6 8 9 10 y = 3 10 6 9 6 8 4 7 st = 6 1 2 5 3 4 7 8 9 10 y = 3 10 6 9 6 8 4 7 6 st = 4 3 5 2 1 6 7 8 9 10 st = 5 3 4 2 1 6 7 8 9 10 y = 3 10 6 9 6 8 4 7 6 3 5 st = 1 2 4 3 5 6 7 8 9 10 st = 4 2 1 3 5 6 7 8 9 10 y = 3 10 6 9 6 8 4 7 6 3 5 3 4 st = 3 1 2 4 5 6 7 8 9 10 y = 3 10 6 9 6 8 4 7 6 3 5 3 4 3 st = 2 1 3 4 5 6 7 8 9 10 y = 3 10 6 9 6 8 4 7 6 3 5 3 4 3 2 st = 1 2 3 4 5 6 7 8 9 10 st = 11 7 2 8 9 1 5 10 6 4 3 y = 10 11 st = 3 4 6 10 5 1 9 8 2 7 11 st = 10 6 4 3 5 1 9 8 2 7 11 y = 10 11 4 10 st = 7 2 8 9 1 5 3 4 6 10 11 st = 9 8 2 7 1 5 3 4 6 10 11 y = 10 11 4 10 4 9 st = 6 4 3 5 1 7 2 8 9 10 11 st = 8 2 7 1 5 3 4 6 9 10 11 y = 10 11 4 10 4 9 8 8 st = 6 4 3 5 1 7 2 8 9 10 11 st = 7 1 5 3 4 6 2 8 9 10 11 y = 10 11 4 10 4 9 8 8 6 7 st = 2 6 4 3 5 1 7 8 9 10 11 st = 6 2 4 3 5 1 7 8 9 10 11 y = 10 11 4 10 4 9 8 8 6 7 2 6 st = 1 5 3 4 2 6 7 8 9 10 11 st = 5 1 3 4 2 6 7 8 9 10 11 y = 10 11 4 10 4 9 8 8 6 7 2 6 2 5 st = 2 4 3 1 5 6 7 8 9 10 11 st = 4 2 3 1 5 6 7 8 9 10 11 y = 10 11 4 10 4 9 8 8 6 7 2 6 2 5 2 4 st = 1 3 2 4 5 6 7 8 9 10 11 st = 3 1 2 4 5 6 7 8 9 10 11 y = 10 11 4 10 4 9 8 8 6 7 2 6 2 5 2 4 2 3 st = 2 1 3 4 5 6 7 8 9 10 11 y = 10 11 4 10 4 9 8 8 6 7 2 6 2 5 2 4 2 3 2 st = 1 2 3 4 5 6 7 8 9 10 11 st = 12 8 10 4 11 7 1 5 3 9 6 2 y = 6 12 st = 2 6 9 3 5 1 7 11 4 10 8 12 st = 11 7 1 5 3 9 6 2 4 10 8 12 y = 6 12 8 11 st = 8 10 4 2 6 9 3 5 1 7 11 12 st = 10 8 4 2 6 9 3 5 1 7 11 12 y = 6 12 8 11 2 10 st = 7 1 5 3 9 6 2 4 8 10 11 12 st = 9 3 5 1 7 6 2 4 8 10 11 12 y = 6 12 8 11 2 10 5 9 st = 8 4 2 6 7 1 5 3 9 10 11 12 y = 6 12 8 11 2 10 5 9 8 st = 3 5 1 7 6 2 4 8 9 10 11 12 st = 7 1 5 3 6 2 4 8 9 10 11 12 y = 6 12 8 11 2 10 5 9 8 4 7 st = 4 2 6 3 5 1 7 8 9 10 11 12 st = 6 2 4 3 5 1 7 8 9 10 11 12 y = 6 12 8 11 2 10 5 9 8 4 7 3 6 st = 1 5 3 4 2 6 7 8 9 10 11 12 st = 5 1 3 4 2 6 7 8 9 10 11 12 y = 6 12 8 11 2 10 5 9 8 4 7 3...

7   Pass
% this test may be extended and rescored sets = { [10 3 2 1 6 5 4 8 7 9] [10:-1:1] [1:10] [2:2:10 1:2:9] [ 9 8 14 5 12 1 10 13 2 7 6 3 15 4 11] [ 7 8 16 13 11 1 9 15 2 6 3 12 10 4 14 5] [ 15 14 19 1 9 4 12 3 16 7 13 20 6 2 11 10 17 5 8 18] [ 2 15 18 4 8 16 10 6 3 14 1 7 20 9 11 12 13 5 19 17 21] [ 5 1 9 3 18 22 17 15 11 16 10 13 2 21 20 6 12 7 23 8 19 14 4] [ 3 9 18 15 7 8 6 10 11 17 21 23 22 1 14 5 2 13 16 12 20 4 19] [ 34 71 51 31 55 61 18 26 59 8 14 6 70 1 25 7 9 4 44 39 19 56 22 32 27 2 11 28 68 57 49 48 20 29 13 10 17 40 3 37 45 63 73 30 43 42 38 21 23 46 62 47 58 69 24 65 60 36 72 64 54 33 5 52 67 66 15 53 12 35 41 16 50]}; for k = 1:numel(sets) x = sets{k}; queue = sort_pancakes(x); for spatula = queue x(1:spatula) = flip(x(1:spatula)); end assert(issorted(x)) n(k) = numel(x); score(k) = numel(queue); end SetSolutionScore(sum(score)); fprintf('\nTest %3d. %3d pancakes, %3d flips',[1:numel(sets); n; score]);

y = 10 st = 9 7 8 4 5 6 1 2 3 10 y = 10 9 st = 3 2 1 6 5 4 8 7 9 10 st = 8 4 5 6 1 2 3 7 9 10 y = 10 9 7 8 st = 7 3 2 1 6 5 4 8 9 10 y = 10 9 7 8 7 st = 4 5 6 1 2 3 7 8 9 10 st = 6 5 4 1 2 3 7 8 9 10 y = 10 9 7 8 7 3 6 st = 3 2 1 4 5 6 7 8 9 10 st = 5 4 1 2 3 6 7 8 9 10 y = 10 9 7 8 7 3 6 5 5 st = 3 2 1 4 5 6 7 8 9 10 st = 4 1 2 3 5 6 7 8 9 10 y = 10 9 7 8 7 3 6 5 5 4 4 st = 3 2 1 4 5 6 7 8 9 10 y = 10 9 7 8 7 3 6 5 5 4 4 3 st = 1 2 3 4 5 6 7 8 9 10 st = 2 1 3 4 5 6 7 8 9 10 y = 10 9 7 8 7 3 6 5 5 4 4 3 2 2 st = 1 2 3 4 5 6 7 8 9 10 y = 10 st = 1 2 3 4 5 6 7 8 9 10 st = 9 8 7 6 5 4 3 2 1 10 y = 10 9 9 st = 1 2 3 4 5 6 7 8 9 10 st = 8 7 6 5 4 3 2 1 9 10 y = 10 9 9 8 8 st = 1 2 3 4 5 6 7 8 9 10 st = 7 6 5 4 3 2 1 8 9 10 y = 10 9 9 8 8 7 7 st = 1 2 3 4 5 6 7 8 9 10 st = 6 5 4 3 2 1 7 8 9 10 y = 10 9 9 8 8 7 7 6 6 st = 1 2 3 4 5 6 7 8 9 10 st = 5 4 3 2 1 6 7 8 9 10 y = 10 9 9 8 8 7 7 6 6 5 5 st = 1 2 3 4 5 6 7 8 9 10 st = 4 3 2 1 5 6 7 8 9 10 y = 10 9 9 8 8 7 7 6 6 5 5 4 4 st = 1 2 3 4 5 6 7 8 9 10 st = 3 2 1 4 5 6 7 8 9 10 y = 10 9 9 8 8 7 7 6 6 5 5 4 4 3 3 st = 1 2 3 4 5 6 7 8 9 10 st = 2 1 3 4 5 6 7 8 9 10 y = 10 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 st = 1 2 3 4 5 6 7 8 9 10 st = 9 8 7 6 5 4 3 2 1 10 y = 9 9 st = 1 2 3 4 5 6 7 8 9 10 st = 8 7 6 5 4 3 2 1 9 10 y = 9 9 8 8 st = 1 2 3 4 5 6 7 8 9 10 st = 7 6 5 4 3 2 1 8 9 10 y = 9 9 8 8 7 7 st = 1 2 3 4 5 6 7 8 9 10 st = 6 5 4 3 2 1 7 8 9 10 y = 9 9 8 8 7 7 6 6 st = 1 2 3 4 5 6 7 8 9 10 st = 5 4 3 2 1 6 7 8 9 10 y = 9 9 8 8 7 7 6 6 5 5 st = 1 2 3 4 5 6 7 8 9 10 st = 4 3 2 1 5 6 7 8 9 10 y = 9 9 8 8 7 7 6 6 5 5 4 4 st = 1 2 3 4 5 6 7 8 9 10 st = 3 2 1 4 5 6 7 8 9 10 y = 9 9 8 8 7 7 6 6 5 5 4 4 3 3 st = 1 2 3 4 5 6 7 8 9 10 st = 2 1 3 4 5 6 7 8 9 10 y = 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 st = 1 2 3 4 5 6 7 8 9 10 st = 10 8 6 4 2 1 3 5 7 9 y = 5 10 st = 9 7 5 3 1 2 4 6 8 10 y = 5 10 9 st = 8 6 4 2 1 3 5 7 9 10 y = 5 10 9 8 st = 7 5 3 1 2 4 6 8 9 10 y = 5 10 9 8 7 st = 6 4 2 1 3 5 7 8 9 10 y = 5 10 9 8 7 6 st = 5 3 1 2 4 6 7 8 9 10 y = 5 10 9 8 7 6 5 st = 4 2 1 3 5 6 7 8 9 10 y = 5 10 9 8 7 6 5 4 st = 3 1 2 4 5 6 7 8 9 10 y = 5 10 9 8 7 6 5 4 3 st = 2 1 3 4 5 6 7 8 9 10 y = 5 10 9 8 7 6 5 4 3 2 st = 1 2 3 4 5 6 7 8 9 10 st = 15 3 6 7 2 13 10 1 12 5 14 8 9 4 11 y = 13 15 st = 11 4 9 8 14 5 12 1 10 13 2 7 6 3 15 st = 14 8 9 4 11 5 12 1 10 13 2 7 6 3 15 y = 13 15 5 14 st = 3 6 7 2 13 10 1 12 5 11 4 9 8 14 15 st = 13 2 7 6 3 10 1 12 5 11 4 9 8 14 15 y = 13 15 5 14 5 13 st = 8 9 4 11 5 12 1 10 3 6 7 2 13 14 15 st = 12 5 11 4 9 8 1 10 3 6 7 2 13 14 15 y = 13 15 5 14 5 13 6 12 st = 2 7 6 3 10 1 8 9 4 11 5 12 13 14 15 st = 11 4 9 8 1 10 3 6 7 2 5 12 13 14 15 y = 13 15 5 14 5 13 6 12 10 11 st = 5 2 7 6 3 10 1 8 9 4 11 12 13 14 15 st = 10 3 6 7 2 5 1 8 9 4 11 12 13 14 15 y = 13 15 5 14 5 13 6 12 10 11 6 10 st = 4 9 8 1 5 2 7 6 3 10 11 12 13 14 15 st = 9 4 8 1 5 2 7 6 3 10 11 12 13 14 15 y = 13 15 5 14 5 13 6 12 10 11 6 10 2 9 st = 3 6 7 2 5 1 8 4 9 10 11 12 13 14 15 st = 8 1 5 2 7 6 3 4 9 10 11 12 13 14 15 y = 13 15 5 14 5 13 6 12 10 11 6 10 2 9 7 8 st = 4 3 6 7 2 5 1 8 9 10 11 12 13 14 15 st = 7 6 3 4 2 5 1 8 9 10 11 12 13 14 15 y = 13 15 5 14 5 13 6 12 10 11 6 10 2 9 7 8 4 7 st = 1 5 2 4 3 6 7 8 9 10 11 12 13 14 15 st = 6 3 4 2 5 1 7 8 9 10 11 12 13 14 15 y = 13 15 5 14 5 13 6 12 10 11 6 10 2 9 7 8 4 7 6 6 st = 1 5 2 4 3 6 7 8 9 10 11 12 13 14 15 st = 5 1 2 4 3 6 7 8 9 10 11 12 13 14 15 y = 13 15 5 14 5 13 6 12 10 11 6 10 2 9 7 8 4 7 6 6 2 5 st = 3 4 2 1 5 6 7 8 9 10 11 12 13 14 15 st = 4 3 2 1 5 6 7 8 9 10 11 12 13 14 15 y = 13 15 5 14 5 13 6 12 10 11 6 10 2 9 7 8 4 7 6 6 2 5 2 4 st = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 st = 3 2 1 4 5 6 7 8 9 10 11 12 13 14 15 y = 13 15 5 14 5 13 6 12 10 11 6 10 2 9 7 8 4 7 6 6 2 5 2 4 3 3 st = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 st = 2 1 3 4 5 6 7 8 9 10 11 12 13 14 15 y = 13 15 5 14 5 13 6 12 10 11 6 10 2 9 7 8 4 7 6 6 2 5 2 4 3 3 2 2 st = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 st = 1...