Tower of Hanoi (3–8 Discs, with Auto-Solve)
Move the whole stack of discs from the left peg to the right peg, one disc at a time, never placing a larger disc on a smaller one. Your moves are counted and compared with the minimum possible. If you get stuck, let the game play the optimal solution for you. For another brain teaser, try Memory Match.
🔒 Runs in your browser · Your data is never sent to a server
- Moves
- 0
- Minimum moves
- 7
- Best moves
- No record yet
Pick the peg with the disc you want to move. Keys 1 to 3 also select a peg.
How to use
- Choose the "Number of discs" from 3 to 8 (changing it restarts the puzzle).
- Click (or tap) the peg that holds the disc you want to move, then click the peg to move it to. The top disc moves.
- A larger disc cannot go on a smaller one. Move every disc to the right peg to win and compare your moves with the minimum.
- If you get stuck, press "Auto-solve" to watch the optimal solution, and "Stop" to halt it. "Reset" starts over.
Notes
- With n discs the minimum is 2^n − 1 moves (7 for 3 discs, 255 for 8 discs). The optimal solution finishes in exactly that many.
- "Auto-solve" first returns the board to the start and then plays the optimal solution. You cannot move while it plays; press "Stop" to take over.
- A puzzle finished by auto-solve is not saved as a best record.
- Best moves are saved per disc count only in this browser (localStorage) and are never sent to a server. Clearing browser data removes them.
Glossary
Tower of Hanoi
A puzzle with three pegs and discs of different sizes. Discs move one at a time and may only be placed on a larger disc. It is a classic example for teaching recursion.
Minimum moves (2^n − 1)
The fewest moves needed to transfer n discs. It follows from recursion: move n−1 discs aside, move the largest disc once, then bring the n−1 discs back on top.
FAQ
How is the minimum number of moves determined?
With n discs the minimum is 2^n − 1 moves: 7 for 3 discs, 31 for 5 discs and 255 for 8 discs. It is not possible to finish in fewer.
Does auto-solve continue from my current position?
No. It returns the board to the start and plays the optimal solution from the beginning. You cannot move while it plays, but pressing "Stop" lets you carry on from that position yourself.
Can I play without dragging?
Yes. Click or tap the peg holding the disc, then click the peg to move it to. With a keyboard, focus a peg and press Enter or Space, or use the number keys 1 to 3 to select a peg.
Where are my best moves stored?
Per disc count, only in your browser's localStorage; nothing is sent to a server. Puzzles finished with auto-solve are not recorded.
Share this page
