Cody

# Problem 42497. Pancake sorting

Solution 2450355

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 = 1 5 4 3 2 stack = 1 2 3 4 5 ans = 1 ans = 5 ans = 4 ans = 3 ans = 2

Output argument "y" (and maybe others) not assigned during call to "sort_pancakes". Error in Test1 (line 2) for spatula = sort_pancakes(x)

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 = 1 6 5 4 3 2 stack = 6 4 2 5 3 1 ans = 2 ans = 4 ans = 6 ans = 3 ans = 5 ans = 1

Output argument "y" (and maybe others) not assigned during call to "sort_pancakes". Error in Test2 (line 2) for spatula = sort_pancakes(x)

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

t = 1 12 11 10 9 8 7 6 5 4 3 2 stack = 9 12 3 2 8 5 6 10 1 11 4 7 ans = 5 ans = 2 ans = 11 ans = 12 ans = 6 ans = 9 ans = 8 ans = 4 ans = 1 ans = 3 ans = 10 ans = 7

Output argument "y" (and maybe others) not assigned during call to "sort_pancakes". Error in Test3 (line 2) for spatula = sort_pancakes(x)

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

t = 1 13 12 11 10 9 8 7 6 5 4 3 2 stack = 9 3 4 10 2 7 12 13 8 1 11 6 5 ans = 6 ans = 12 ans = 11 ans = 5 ans = 13 ans = 8 ans = 3 ans = 2 ans = 7 ans = 1 ans = 4 ans = 9 ans = 10

Output argument "y" (and maybe others) not assigned during call to "sort_pancakes". Error in Test4 (line 2) for spatula = sort_pancakes(x)

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 stack = 1 ans = 1

Output argument "y" (and maybe others) not assigned during call to "sort_pancakes". Error in Test5 (line 3) for spatula = sort_pancakes(x)