Cody

Problem 42497. Pancake sorting

Solution 2450531

Submitted on 1 Jun 2020
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   Fail
x = 1:5; for spatula = sort_pancakes(x) x(1:spatula) = flip(x(1:spatula)); end assert(issorted(x))

t = 5 4 3 2 1 t = 4 3 2 1 t = 1 4 3 2 1 part1 = 1 part2 = 2 3 4 5 stack = 1 2 3 4 5 y = 1 part1 = 4 3 2 1 part2 = 5 stack = 4 3 2 1 5 y = 1 4 part1 = 3 4 part2 = 2 1 5 stack = 3 4 2 1 5 y = 1 4 2 part1 = 2 4 3 part2 = 1 5 stack = 2 4 3 1 5 y = 1 4 2 3 part1 = 1 3 4 2 part2 = 5 stack = 1 3 4 2 5 y = 1 4 2 3 4

Assertion failed.

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

t = 6 5 4 3 2 1 t = 5 4 3 2 1 t = 1 5 4 3 2 1 part1 = 1 3 5 2 4 6 part2 = 1×0 empty double row vector stack = 1 3 5 2 4 6 y = 6 part1 = 5 3 1 part2 = 2 4 6 stack = 5 3 1 2 4 6 y = 6 3 part1 = 4 2 1 3 5 part2 = 6 stack = 4 2 1 3 5 6 y = 6 3 5 part1 = 3 1 2 4 part2 = 5 6 stack = 3 1 2 4 5 6 y = 6 3 5 4 part1 = 2 1 3 part2 = 4 5 6 stack = 2 1 3 4 5 6 y = 6 3 5 4 3 part1 = 1 2 part2 = 3 4 5 6 stack = 1 2 3 4 5 6 y = 6 3 5 4 3 2

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

t = 12 11 10 9 8 7 6 5 4 3 2 1 t = 11 10 9 8 7 6 5 4 3 2 1 t = 1 11 10 9 8 7 6 5 4 3 2 1 part1 = 1 2 7 6 10 11 9 part2 = 4 5 3 12 8 stack = 1 2 7 6 10 11 9 4 5 3 12 8 y = 7 part1 = 11 10 6 7 2 1 part2 = 9 4 5 3 12 8 stack = 11 10 6 7 2 1 9 4 5 3 12 8 y = 7 6 part1 = 10 11 part2 = 6 7 2 1 9 4 5 3 12 8 stack = 10 11 6 7 2 1 9 4 5 3 12 8 y = 7 6 2 part1 = 9 1 2 7 6 11 10 part2 = 4 5 3 12 8 stack = 9 1 2 7 6 11 10 4 5 3 12 8 y = 7 6 2 7 part1 = 8 12 3 5 4 10 11 6 7 2 1 9 part2 = 1×0 empty double row vector stack = 8 12 3 5 4 10 11 6 7 2 1 9 y = 7 6 2 7 12 part1 = 7 6 11 10 4 5 3 12 8 part2 = 2 1 9 stack = 7 6 11 10 4 5 3 12 8 2 1 9 y = 7 6 2 7 12 9 part1 = 6 7 part2 = 11 10 4 5 3 12 8 2 1 9 stack = 6 7 11 10 4 5 3 12 8 2 1 9 y = 7 6 2 7 12 9 2 part1 = 5 4 10 11 7 6 part2 = 3 12 8 2 1 9 stack = 5 4 10 11 7 6 3 12 8 2 1 9 y = 7 6 2 7 12 9 2 6 part1 = 4 5 part2 = 10 11 7 6 3 12 8 2 1 9 stack = 4 5 10 11 7 6 3 12 8 2 1 9 y = 7 6 2 7 12 9 2 6 2 part1 = 3 6 7 11 10 5 4 part2 = 12 8 2 1 9 stack = 3 6 7 11 10 5 4 12 8 2 1 9 y = 7 6 2 7 12 9 2 6 2 7 part1 = 2 8 12 4 5 10 11 7 6 3 part2 = 1 9 stack = 2 8 12 4 5 10 11 7 6 3 1 9 y = 7 6 2 7 12 9 2 6 2 7 10 part1 = 1 3 6 7 11 10 5 4 12 8 2 part2 = 9 stack = 1 3 6 7 11 10 5 4 12 8 2 9 y = 7 6 2 7 12 9 2 6 2 7 10 11

Assertion failed.

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

t = 13 12 11 10 9 8 7 6 5 4 3 2 1 t = 12 11 10 9 8 7 6 5 4 3 2 1 t = 1 12 11 10 9 8 7 6 5 4 3 2 1 part1 = 1 6 11 8 7 4 12 3 13 10 2 part2 = 5 9 stack = 1 6 11 8 7 4 12 3 13 10 2 5 9 y = 11 part1 = 12 4 7 8 11 6 1 part2 = 3 13 10 2 5 9 stack = 12 4 7 8 11 6 1 3 13 10 2 5 9 y = 11 7 part1 = 11 8 7 4 12 part2 = 6 1 3 13 10 2 5 9 stack = 11 8 7 4 12 6 1 3 13 10 2 5 9 y = 11 7 5 part1 = 10 13 3 1 6 12 4 7 8 11 part2 = 2 5 9 stack = 10 13 3 1 6 12 4 7 8 11 2 5 9 y = 11 7 5 10 part1 = 9 5 2 11 8 7 4 12 6 1 3 13 10 part2 = 1×0 empty double row vector stack = 9 5 2 11 8 7 4 12 6 1 3 13 10 y = 11 7 5 10 13 part1 = 8 11 2 5 9 part2 = 7 4 12 6 1 3 13 10 stack = 8 11 2 5 9 7 4 12 6 1 3 13 10 y = 11 7 5 10 13 5 part1 = 7 9 5 2 11 8 part2 = 4 12 6 1 3 13 10 stack = 7 9 5 2 11 8 4 12 6 1 3 13 10 y = 11 7 5 10 13 5 6 part1 = 6 12 4 8 11 2 5 9 7 part2 = 1 3 13 10 stack = 6 12 4 8 11 2 5 9 7 1 3 13 10 y = 11 7 5 10 13 5 6 9 part1 = 5 2 11 8 4 12 6 part2 = 9 7 1 3 13 10 stack = 5 2 11 8 4 12 6 9 7 1 3 13 10 y = 11 7 5 10 13 5 6 9 7 part1 = 4 8 11 2 5 part2 = 12 6 9 7 1 3 13 10 stack = 4 8 11 2 5 12 6 9 7 1 3 13 10 y = 11 7 5 10 13 5 6 9 7 5 part1 = 3 1 7 9 6 12 5 2 11 8 4 part2 = 13 10 stack = 3 1 7 9 6 12 5 2 11 8 4 13 10 y = 11 7 5 10 13 5 6 9 7 5 11 part1 = 2 5 12 6 9 7 1 3 part2 = 11 8 4 13 10 stack = 2 5 12 6 9 7 1 3 11 8 4 13 10 y = 11 7 5 10 13 5 6 9 7 5 11 8 part1 = 1 7 9 6 12 5 2 part2 = 3 11 8 4 13 10 stack = 1 7 9 6 12 5 2 3 11 8 4 13 10 y = 11 7 5 10 13 5 6 9 7 5 11 8 7

Assertion failed.

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

t = 1 t = 1×0 empty double row vector t = 1 part1 = 1 part2 = 1×0 empty double row vector stack = 1 y = 1 t = 2 1 t = 1 t = 1 1 part1 = 1 2 part2 = 1×0 empty double row vector stack = 1 2 y = 2 part1 = 1 part2 = 2 stack = 1 2 y = 2 1 t = 3 2 1 t = 2 1 t = 1 2 1 part1 = 1 2 part2 = 3 stack = 1 2 3 y = 2 part1 = 2 1 part2 = 3 stack = 2 1 3 y = 2 2 part1 = 1 2 part2 = 3 stack = 1 2 3 y = 2 2 2 t = 4 3 2 1 t = 3 2 1 t = 1 3 2 1 part1 = 1 4 part2 = 3 2 stack = 1 4 3 2 y = 2 part1 = 3 4 1 part2 = 2 stack = 3 4 1 2 y = 2 3 part1 = 2 1 4 3 part2 = 1×0 empty double row vector stack = 2 1 4 3 y = 2 3 4 part1 = 1 2 part2 = 4 3 stack = 1 2 4 3 y = 2 3 4 2

Assertion failed.

Suggested Problems

More from this Author41