Cody

Solution 1940590

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
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

2   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

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

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

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

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

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

Suggested Problems

More from this Author47