Problem 42497. Pancake sorting
Sort a stack of pancakes by flipping them using spatula.
- There are N pancakes with diameters 1:N.
- Spatula can be inserted anywhere in the stack and used to flip all the pancakes above.
- Sort pancakes in increasing order.
- Return a vector of places where spatula was inserted.
- References: math.illinois.edu, wikipedia.
Example (horizontal view):
Initial stack: 6 4 2 5 3 1, ("," indicates position of spatula) first flip: 1 3 5,2 4 6 second: 5 3 1 2 4,6 ... 4 2 1 3,5 6 3 1 2,4 5 6 2 1,3 4 5 6 sorted! 1 2 3 4 5 6
positions of spatula from the begining: 6 3 5 4 3 2
Solution Stats
Problem Comments
-
1 Comment
David Verrelli
on 12 Oct 2017
The flipping sequence does not need to be the most efficient, it just needs to (eventually) have the desired effect.
Solution Comments
Show commentsProblem Recent Solvers40
Suggested Problems
-
It dseon't mettar waht oedrr the lrettes in a wrod are.
1809 Solvers
-
Reverse the Words (not letters) of a String
440 Solvers
-
Construct an index vector from two input vectors in vectorized fashion
390 Solvers
-
Integer Sequence - II : New Fibonacci
491 Solvers
-
150 Solvers
More from this Author40
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!