Tower of Hanoi
The Tower of Hanoi is a classic math puzzle from 1883: shift a stack of discs from one peg to another, one disc at a time, never placing a bigger disc on a smaller one. Can you do it in the minimum number of moves?
How to play Tower of Hanoi
- All the discs start on peg A, largest at the bottom. Your goal is to rebuild the whole tower on peg B or peg C.
- Move one disc at a time: take the top disc of any peg and put it on another peg.
- A disc may only go onto an empty peg or onto a larger disc.
- The counter shows your moves next to the minimum possible, which is 2n − 1 for n discs (7 for 3 discs, 31 for 5, 1023 for 10).
- Your best result for each number of discs is saved. Using Show me finishes the puzzle for you, but that run does not count as a best.
Controls
- Tap a peg to lift its top disc, then tap the peg to drop it on — or drag the disc there
- Keys 1, 2, 3 (or A, B, C) pick pegs · Z undo · S show me · Esc put the disc back
Tips
- The smallest disc moves on every other turn. With an odd number of discs, cycle it A → C → B → A; with an even number, A → B → C → A.
- On the turns between, there is only ever one legal move that does not touch the smallest disc — make it.
- Think recursively: to move a tower of 5, move the top 4 out of the way, move the big disc, then move the 4 back on top of it.
- Start with 3 discs, get a perfect 7-move solve, then add one disc at a time.
FAQ
What is the minimum number of moves in the Tower of Hanoi?
For n discs it is 2n − 1: 7 moves for 3 discs, 15 for 4, 31 for 5, 63 for 6 and 1023 for 10. Each extra disc doubles the work plus one move.
How do you solve the Tower of Hanoi?
Move the smallest disc in a fixed direction every second move, and in between make the only other legal move. Or think recursively: move all but the bottom disc aside, move the bottom disc, then rebuild on top of it.
Why is it called the Tower of Hanoi?
A French mathematician published the puzzle in 1883 with a story about monks moving 64 golden discs; the name was part of that invented legend. With 64 discs, the minimum would take more than 18 quintillion moves.
Does undo count as a move?
Yes. Undo takes a disc back, but the counter keeps every move you made, so a perfect score means no wasted moves at all.
Is my progress saved?
Your current puzzle, its timer and your best moves and time for every disc count are saved in this browser.