Stack Order

Runs entirely on your device โ€” works with the network off, no ads, no account, no tracking.

  • Works offline
  • Keyboard playable
  • Screen-reader playable
  • No ads, no account
  • No betting, no money, no prizes
  • 2โ€“4 minAll ages

How do you solve the Tower of Hanoi from a random starting position?

Start at the biggest disc, not the smallest. Ask where the largest disc has to finish. If it is already on the goal stack it never moves again, so forget it and ask the same question about the next size down. If it is not, then it has exactly one job โ€” cross to the goal stack โ€” and it cannot move until every smaller disc is parked on the one stack that is neither its home nor its destination. That is now a smaller version of the identical problem, so ask it again about the next disc down, and again, until you reach the smallest disc, which can always move anywhere. Follow that chain and you have the whole solution before you touch anything. It works from any position, which is why it beats the memorised "move the small one in a fixed cycle" recipe โ€” that recipe only ever worked from a perfect tower.

Moves 0 / 21Shortest from here 15Par 15Off line 0

Shortest line from here: 15 moves. 21 moves left. Cursor on stack A.

โ† โ†’ choose a stack ยท โ†‘ lift its top disc ยท โ†“ set the disc down ยท Enter does both ยท Esc puts it back. Click the board first, or press Tab to focus it.

What this builds

SKILL โ€” plan from the largest piece down, and notice the exact move where you leave the shortest line

Rebuild the tower, and watch the count

Five discs, three stacks, one disc at a time, and a bigger disc may never sit on a smaller one. Move them until the whole tower stands on the goal stack. The twist is the number above the board: it is the exact shortest line from the position in front of you, recalculated after every move โ€” so the moment you wander off it, the board says so.

Unlike the puzzle you were taught, this one never opens on a neat tower. It opens somewhere in the middle, on a position picked because a perfect player needs between twelve and twenty-two moves from it. The recited solution does not apply. You have to read the board.

It runs entirely on your device: 0 network requests, works offline. No ads, no account, nothing to buy, and no betting, money or prizes of any kind.

How to play

  1. Focus the board โ€” click it, or press Tab until it is focused.
  2. Choose a stack with the left and right arrow keys.
  3. Lift its top disc with the up arrow, or with Enter.
  4. Set the disc down on another stack with the down arrow, or with Enter again โ€” it only lands if the disc underneath is bigger, or the stack is empty.
  5. Change your mind with Esc, which puts the disc back where it was and costs nothing.
  6. Watch "shortest from here" after each move: down one means you are on a shortest line, while unchanged or up one means the move bought nothing and still spent your budget.
  7. Finish the tower on the stack marked with a star before the moves run out.

FAQ

How do you solve the Tower of Hanoi from a random starting position?

Start at the biggest disc, not the smallest. Ask where the largest disc has to finish. If it is already on the goal stack it never moves again, so forget it and ask the same question about the next size down. If it is not, then it has exactly one job โ€” cross to the goal stack โ€” and it cannot move until every smaller disc is parked on the one stack that is neither its home nor its destination. That is now a smaller version of the identical problem, so ask it again about the next disc down, and again, until you reach the smallest disc, which can always move anywhere.

Follow that chain and you have the whole solution before you touch anything. It works from any position, which is why it beats the memorised "move the small one in a fixed cycle" recipe โ€” that recipe only ever worked from a perfect tower.

What does the "shortest from here" number mean?

It is the exact number of moves a perfect player would still need, computed from the position on screen rather than estimated. A legal move can only change it by one in either direction, or leave it alone. Down one is progress. Unchanged means the move was legal, cost you one from the budget and brought you no nearer. Up one means you undid something. Watching that single digit is the fastest way to learn which of your instincts about this puzzle are wrong.

Is every board actually solvable?

Yes, and by construction rather than by checking. A position here is stored as which stack each disc is on, and the order inside a stack is forced โ€” bigger always below smaller โ€” so every possible arrangement is a legal one. Any legal arrangement can reach any other, so nothing that can be dealt can be impossible. The move budget is that board's own shortest line plus six spare moves, so the budget is always enough as well.

Why is the classic starting tower never dealt?

Because it is too long and too well known. A perfect tower on the wrong stack is exactly thirty-one moves from finished with five discs, which is above the band this game deals from, so it can never come up. Every board you get is somewhere in the middle of the puzzle, where the memorised routine has nothing to say.

Do I need to see colour to play this?

No. A disc's size is printed on it as a number and repeated as its width, the goal stack carries a star and the word "goal", and the disc in your hand is marked with an arrow and a dashed edge. Nothing in the game is carried by hue, so it reads the same in greyscale and in a forced-colours theme.

Is there any money, betting or in-app purchase in this?

None, and there never will be. There is no currency, nothing to buy, no extra moves for sale and no prize of any kind. The score is a number on your own device.

Does it work offline?

Yes. Once the page has loaded once, the whole game is on your device and nothing is sent anywhere. Turn the network off and it plays exactly the same.

Can I play it with a keyboard or a screen reader?

Both, fully. Arrows choose a stack and lift or set down a disc, Enter does both, Esc puts a disc back. Each stack announces its contents from the bottom up, whether it is the goal, and whether its top disc is currently lifted, and the shortest line from the current position is read out after every move.

Limits

Five discs and three stacks, so the deepest possible position is thirty-one moves from finished. The generator only deals positions between twelve and twenty-two moves out, and always allows six moves more than perfect play needs. There is no undo of a completed move โ€” putting a lifted disc back is free, but once it has landed it counts.

Related

Colour Sort is the other stack puzzle here and rewards the same habit: decide where everything has to finish before you move anything. Slide Fifteen makes the same point on a grid.

Bookmark this page (Ctrl+D, or โŒ˜D on Mac) or install the app โ€” it works offline the next time you need it.

Have a question or feedback about this game?

Private: this note isn't tracked, and nothing you did in this game is sent โ€” only what you type here.