Cody

# Problem 42497. Pancake sorting

Solution 2450483

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 = 5 4 3 2 part1 = 5 4 3 2 1 part2 = 1×0 empty double row vector stack = 5 4 3 2 1 y = 5 part1 = 4 5 part2 = 3 2 1 stack = 4 5 3 2 1 y = 5 2 part1 = 3 5 4 part2 = 2 1 stack = 3 5 4 2 1 y = 5 2 3 part1 = 2 4 5 3 part2 = 1 stack = 2 4 5 3 1 y = 5 2 3 4

Assertion failed.

2   Fail
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 = 6 5 4 3 2 part1 = 6 part2 = 4 2 5 3 1 stack = 6 4 2 5 3 1 y = 1 part1 = 5 2 4 6 part2 = 3 1 stack = 5 2 4 6 3 1 y = 1 4 part1 = 4 2 5 part2 = 6 3 1 stack = 4 2 5 6 3 1 y = 1 4 3 part1 = 3 6 5 2 4 part2 = 1 stack = 3 6 5 2 4 1 y = 1 4 3 5 part1 = 2 5 6 3 part2 = 4 1 stack = 2 5 6 3 4 1 y = 1 4 3 5 4

Assertion failed.

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 = 12 11 10 9 8 7 6 5 4 3 2 part1 = 12 3 9 1 11 2 8 7 4 part2 = 6 10 5 stack = 12 3 9 1 11 2 8 7 4 6 10 5 y = 9 part1 = 11 1 9 3 12 part2 = 2 8 7 4 6 10 5 stack = 11 1 9 3 12 2 8 7 4 6 10 5 y = 9 5 part1 = 10 6 4 7 8 2 12 3 9 1 11 part2 = 5 stack = 10 6 4 7 8 2 12 3 9 1 11 5 y = 9 5 11 part1 = 9 3 12 2 8 7 4 6 10 part2 = 1 11 5 stack = 9 3 12 2 8 7 4 6 10 1 11 5 y = 9 5 11 9 part1 = 8 2 12 3 9 part2 = 7 4 6 10 1 11 5 stack = 8 2 12 3 9 7 4 6 10 1 11 5 y = 9 5 11 9 5 part1 = 7 9 3 12 2 8 part2 = 4 6 10 1 11 5 stack = 7 9 3 12 2 8 4 6 10 1 11 5 y = 9 5 11 9 5 6 part1 = 6 4 8 2 12 3 9 7 part2 = 10 1 11 5 stack = 6 4 8 2 12 3 9 7 10 1 11 5 y = 9 5 11 9 5 6 8 part1 = 5 11 1 10 7 9 3 12 2 8 4 6 part2 = 1×0 empty double row vector stack = 5 11 1 10 7 9 3 12 2 8 4 6 y = 9 5 11 9 5 6 8 12 part1 = 4 8 2 12 3 9 7 10 1 11 5 part2 = 6 stack = 4 8 2 12 3 9 7 10 1 11 5 6 y = 9 5 11 9 5 6 8 12 11 part1 = 3 12 2 8 4 part2 = 9 7 10 1 11 5 6 stack = 3 12 2 8 4 9 7 10 1 11 5 6 y = 9 5 11 9 5 6 8 12 11 5 part1 = 2 12 3 part2 = 8 4 9 7 10 1 11 5 6 stack = 2 12 3 8 4 9 7 10 1 11 5 6 y = 9 5 11 9 5 6 8 12 11 5 3

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 = 13 12 11 10 9 8 7 6 5 4 3 2 part1 = 13 8 4 9 part2 = 11 6 10 2 1 5 7 12 3 stack = 13 8 4 9 11 6 10 2 1 5 7 12 3 y = 4 part1 = 12 7 5 1 2 10 6 11 9 4 8 13 part2 = 3 stack = 12 7 5 1 2 10 6 11 9 4 8 13 3 y = 4 12 part1 = 11 6 10 2 1 5 7 12 part2 = 9 4 8 13 3 stack = 11 6 10 2 1 5 7 12 9 4 8 13 3 y = 4 12 8 part1 = 10 6 11 part2 = 2 1 5 7 12 9 4 8 13 3 stack = 10 6 11 2 1 5 7 12 9 4 8 13 3 y = 4 12 8 3 part1 = 9 12 7 5 1 2 11 6 10 part2 = 4 8 13 3 stack = 9 12 7 5 1 2 11 6 10 4 8 13 3 y = 4 12 8 3 9 part1 = 8 4 10 6 11 2 1 5 7 12 9 part2 = 13 3 stack = 8 4 10 6 11 2 1 5 7 12 9 13 3 y = 4 12 8 3 9 11 part1 = 7 5 1 2 11 6 10 4 8 part2 = 12 9 13 3 stack = 7 5 1 2 11 6 10 4 8 12 9 13 3 y = 4 12 8 3 9 11 9 part1 = 6 11 2 1 5 7 part2 = 10 4 8 12 9 13 3 stack = 6 11 2 1 5 7 10 4 8 12 9 13 3 y = 4 12 8 3 9 11 9 6 part1 = 5 1 2 11 6 part2 = 7 10 4 8 12 9 13 3 stack = 5 1 2 11 6 7 10 4 8 12 9 13 3 y = 4 12 8 3 9 11 9 6 5 part1 = 4 10 7 6 11 2 1 5 part2 = 8 12 9 13 3 stack = 4 10 7 6 11 2 1 5 8 12 9 13 3 y = 4 12 8 3 9 11 9 6 5 8 part1 = 3 13 9 12 8 5 1 2 11 6 7 10 4 part2 = 1×0 empty double row vector stack = 3 13 9 12 8 5 1 2 11 6 7 10 4 y = 4 12 8 3 9 11 9 6 5 8 13 part1 = 2 1 5 8 12 9 13 3 part2 = 11 6 7 10 4 stack = 2 1 5 8 12 9 13 3 11 6 7 10 4 y = 4 12 8 3 9 11 9 6 5 8 13 8

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 = 2 1 t = 2 part1 = 2 1 part2 = 1×0 empty double row vector stack = 2 1 y = 2

Assertion failed.