About Tower of Hanoi
Tower of Hanoi is a free logic puzzle: move the whole stack of discs to another peg, never placing a larger disc on a smaller one.
Tower of Hanoi is a classic puzzle with three pegs and a stack of discs. Your goal is to move the whole stack from the left peg to the right peg, one disc at a time, without ever putting a bigger disc on top of a smaller one.
Choose between 3 and 8 discs. With n discs the fewest possible moves is 2 to the power of n, minus 1, so 3 discs take 7 moves and 8 discs take 255. The game counts your moves, shows the minimum, and can give you a hint.
How to play Tower of Hanoi
- Choose how many discs to play with, from 3 to 8.
- Tap a peg to pick up its top disc, then tap another peg to put the disc down there.
- You can only move one disc at a time, and only the top disc of a peg.
- A disc can only go on an empty peg or on a larger disc, never on a smaller one.
- Move the whole stack to the right-hand peg. Try to finish in the fewest moves, which is 2ⁿ − 1 for n discs.
Tower of Hanoi tips and strategy
- With an odd number of discs, move the smallest disc to the destination peg first. With an even number, move it to the middle peg first.
- Move the smallest disc every other turn, always in the same direction around the pegs. The moves in between are forced because only one other move is legal.
- To move a stack of n discs, move the top n−1 discs to the spare peg, move the biggest disc across, then move the n−1 discs on top of it.
- Learn the pattern on 3 discs before trying 5 or more. The same pattern scales up.
- Use Hint when you are stuck. It always shows a move that is part of the shortest solution from your current position.
Frequently asked questions
How do you solve the Tower of Hanoi?
Move the smallest disc every other turn, always in the same direction around the three pegs. In between, make the only other legal move. This takes the fewest possible moves.
What is the minimum number of moves?
For n discs it is 2ⁿ − 1. That is 7 moves for 3 discs, 15 for 4, 31 for 5, 63 for 6, 127 for 7 and 255 for 8.
What are the rules of the Tower of Hanoi?
Move one disc at a time, only the top disc of a stack, and never place a larger disc on a smaller one. The aim is to move the whole stack to another peg.
Which peg should the stack end on?
In this game the goal is the right-hand peg.
Who invented the Tower of Hanoi?
The French mathematician Édouard Lucas invented it and sold it as a toy in 1883.
Why is it used in computer science?
It is a standard example of recursion, where a big problem is solved by solving smaller copies of itself. The number of moves doubles with every extra disc.
How does the Hint button work?
Hint highlights the next move of the shortest solution from your current position, even if you have already made mistakes.
Are my best scores saved?
Yes. Your fewest moves for each number of discs is saved in your browser on this device.