Sorting a stack with nothing but prefix flips
This article walks through the only move available in the pancake puzzle, the greedy method that always works, the flip budgets on each level, and the thinking traps that waste moves.

What you are sorting and how
A stack of pancakes sits in a column, each one a different size. They are in the wrong order. Your job is to sort them so the biggest one is on the bottom and the smallest one is on top. The only move you have is a prefix flip: pick any pancake in the stack, and everything from that pancake to the top of the pile flips over together.
Think of sliding a spatula under one pancake and turning the whole top portion upside down. The pancake you chose is now on top, and everything that was above it is now below it in reverse order. Nothing below the spatula moves at all.
You have a limited number of flips. Sort the stack before you run out and you win. Run out of flips with the stack still jumbled and the puzzle ends.
How the controls work
Tap or click any pancake in the stack. That pancake and everything above it will flip over in one move. The flip counter goes up by one and the remaining flips go down by one.
Each pancake shows its size as a number. The widest pancake on screen is the one with the highest number. The narrowest is size one. When all the numbers read in order from top to bottom, smallest at the top, the stack is sorted and the puzzle is solved.
The stat bar at the top tracks three things: how many flips you have used, how many flips you have left, and how many pancakes are already in their correct spot counting from the bottom up.
The greedy method that always works
There is a simple method that solves every stack. Start from the biggest pancake that is not yet in its correct place. Flip it to the top. Then flip the whole stack down to the position where that pancake belongs. Two flips and one pancake is home.
Now ignore the bottom of the stack, where the sorted pancakes sit, and repeat. Find the next biggest one out of place, flip it to the top, flip it down. Two flips each, every single time.
For a stack of eight, this method needs at most thirteen flips. For six it needs nine, and for ten it needs seventeen. The limits on each level are set from this formula with a few spare, so a clean greedy run always fits inside the budget.
Saving flips by skipping
Sometimes the biggest unsorted pancake is already on top. When that happens, you can skip the first flip and go straight to the second one, sending it down to its place in a single move instead of two. That saves one flip from your budget.
Watch for this before every pair of flips. If the pancake you need happens to be sitting on top already, you get a free half-turn. Over a full stack, two or three of these lucky breaks add up to a much lower flip count.
The in-place counter at the top tells you how many are already sorted from the bottom up. If it jumps by two or three after one flip, something fell into place by accident. Take a moment to read the stack before your next move so you do not undo it.
Why doing better is genuinely hard
The greedy method works, but it is not the shortest possible sequence of flips. Finding the shortest sequence is what computer scientists call NP-hard, which means there is no known fast algorithm that always finds it.
For small stacks you can sometimes spot a shortcut. Maybe flipping three pancakes instead of two brings two of them closer to home at once. But for a stack of ten, the number of possible flip sequences is enormous, and spotting the best one by eye is close to impossible.
The puzzle does not ask you to be optimal. It asks you to be efficient. The greedy method is efficient. Wandering around making random flips is not, and the budget is not large enough to allow much wandering.
Thinking about the bottom first
It helps to look at the stack from the bottom. The biggest pancake must end up at the bottom. If it is not already there, fixing it is your first job. Once it is in place, pretend it does not exist. Now the second biggest must be at the bottom of what remains. Work downward through the sizes, and the stack sorts itself from the ground up.
This bottom-first thinking is what makes the greedy method feel natural. You are not trying to sort the whole stack at once. You are just asking one question each time: where is the biggest one that is still out of place? Find it, bring it to the top, put it home. Then shrink the problem by one and ask again.
The three difficulty levels
On Easy the stack has six pancakes and the budget gives you four extra flips beyond what the greedy method needs. On Normal the stack grows to eight pancakes with three spare flips. On Hard there are ten pancakes and only two spare flips.
The jump from six to eight pancakes does not just add two more items. It makes the visual scan harder. With six pancakes you can see the whole ordering at a glance. With ten, you have to read the numbers to find the biggest one out of place, and a single careless flip can scramble three that were already right.
The shrinking slack is the real challenge on the higher levels. On Easy you can afford a few wasted flips and still finish. On Hard, almost every flip has to count and there is very little room for error.
Mistakes that waste flips
Most failed attempts come from the same few habits.
- Flipping a pancake that is already in its correct place. Check the in-place counter before each move. If a pancake is already home, leave it alone.
- Working from the top down instead of from the biggest outward. Sorting the smallest first seems natural but it does not work. Every flip to move a small one to the top also moves big ones, and you end up undoing progress.
- Flipping at random hoping the stack will fall into order. The budget is not large enough for trial and error. Pick the biggest unsorted pancake, flip it to the top, flip it home.
- Ignoring pancakes that happen to be on top already. If the biggest unsorted one is already at the top, skip straight to the second flip. Missing this chance costs you one flip you might need later.
- Rushing through without reading the stack. After each flip, stop and look at what changed. A quick scan of the numbers prevents the next move from undoing a pancake that just fell into place.
Reading the stack between moves
After every flip, pause for a moment and scan the stack from the bottom up. Count how many are already in order. Then find the biggest number that is out of place. That is your next target.
The width of each pancake bar on screen matches its size, so a quick glance at the shape of the stack tells you whether it is getting closer to a neat staircase from wide at the bottom to narrow at the top. When the shape looks right but one or two are swapped, you are close. When the whole thing looks jagged, you still have work to do.
This pause takes a second but it saves flips. A move made after reading the stack is almost always the right one. A move made in a hurry is the one that costs the game.
Everything runs on your device
The stack, the flip logic, and the score counter all run inside your browser. Nothing is uploaded to any server. There is no account and no sign-up required. Your best flip count is saved in your browser's local storage on this device alone, and it is never sent anywhere else. Once the page has loaded, the puzzle works offline. Close the tab and the session ends.
