Cody

Problem 42497. Pancake sorting

Solution 2950981

Submitted on 15 Sep 2020 by Catherine Jones
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))

count = 0 y = 1 wstack = 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))

count = 0 y = 6 3 5 4 3 2 wstack = 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))

count = 0 y = 10 12 11 4 10 2 9 2 8 7 6 4 5 3 4 2 3 wstack = 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))

count = 0 y = 12 13 3 12 2 11 9 10 4 9 7 8 6 7 4 6 2 5 2 4 wstack = 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

count = 0 y = 1 wstack = 1 count = 0 y = 2 wstack = 1 2 count = 0 y = 2 wstack = 1 2 3 count = 0 y = 4 3 wstack = 1 2 3 4 count = 0 y = 5 2 4 wstack = 1 2 3 4 5 count = 0 y = 6 4 5 2 4 2 3 wstack = 1 2 3 4 5 6 count = 0 y = 2 7 5 6 4 5 2 4 3 2 wstack = 1 2 3 4 5 6 7 count = 0 y = 4 8 4 6 5 4 3 2 wstack = 1 2 3 4 5 6 7 8 count = 0 y = 2 7 4 6 4 5 2 4 3 wstack = 1 2 3 4 5 6 7 8 9 count = 0 y = 10 6 7 3 6 5 wstack = 1 2 3 4 5 6 7 8 9 10 count = 0 y = 10 2 9 2 7 6 2 5 4 3 wstack = 1 2 3 4 5 6 7 8 9 10 11 count = 0 y = 6 12 10 11 6 10 4 8 4 7 2 6 2 5 4 2 wstack = 1 2 3 4 5 6 7 8 9 10 11 12 count = 0 y = 4 13 2 12 4 11 8 10 3 9 5 8 3 7 5 6 5 2 4 2 3 wstack = 1 2 3 4 5 6 7 8 9 10 11 12 13 count = 0 y = 10 14 3 13 8 12 6 11 5 10 3 9 6 8 3 7 5 6 3 5 3 4 2 3 2 wstack = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 count = 0 y = 2 15 13 14 9 13 7 12 5 11 8 9 3 8 3 7 4 5 2 4 wstack = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 count = 0 y = 13 16 4 15 10 14 9 13 4 12 6 11 9 10 5 8 6 7 2 6 5 2 4 wstack = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 count = 0 y = 2 16 11 15 14 11 13 2 12 3 11 7 10 3 9 7 5 6 3 5 3 wstack = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 count = 0 y = 5 18 5 17 15 16 12 15 12 14 11 13 5 11 4 10 8 9 2 8 5 7 4 6 5 2 4 2 3 wstack = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 count = 0 y = 8 19 9 18 14 17 15 16 8 15 14 9 13 9 12 7 11 6 10 7 9 4 8 2 7 2 6 2 5 2 wstack = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 count = 0 y = 19 20 13 18 10 17 12 16 11 15 14 8 13 4 12 5 11 9 10 4 9 2 8 5 7 6 3 4 3 2 wstack = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

Suggested Problems

More from this Author41

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!