The Tower of Hanoi is one of the most famous mathematical puzzles in history, invented by French mathematician Édouard Lucas in 1883. Move a stack of discs from one peg to another, following one simple rule: a larger disc can never be placed on top of a smaller one. Play Tower of Hanoi online free and discover why this elegant puzzle has fascinated mathematicians, computer scientists, and puzzle lovers for over a century. The minimum number of moves required doubles with each added disc — 5 discs need just 31 moves, but 8 discs need 255! The Tower of Hanoi teaches recursive thinking and planning ahead. It's a wonderful introduction to algorithmic concepts for students, and a satisfying mental challenge for anyone who enjoys puzzles. Choose your disc count and try to solve it in the minimum number of moves.
How to Play Tower of Hanoi
All discs start stacked on the leftmost peg, largest at the bottom. Your goal is to move the entire stack to the rightmost peg. Click a peg to pick up its top disc, then click another peg to place it there.
The rules are simple: you can only move one disc at a time, and you can never place a larger disc on top of a smaller one. The challenge is figuring out the sequence of moves that accomplishes the transfer.
The minimum number of moves for n discs is 2^n - 1. For 5 discs, that's 31 moves. A move counter tracks your progress, and the par display shows the theoretical minimum. Try to match par for a perfect solve!
Tower of Hanoi Tips & Strategies
- Start by solving with 3 discs to learn the pattern before attempting more.
- Focus on moving the largest uncovered disc to its destination — solve sub-problems recursively.
- The smallest disc always moves first and moves every other turn in the optimal solution.
- Think of it as: move the top n-1 discs to the middle peg, move the largest to the goal, then move n-1 from middle to goal.
- The optimal solution follows a simple pattern — once you see it, you'll never forget it.
- For an even number of discs, the first move goes to the middle peg; for odd, to the right peg.
Frequently Asked Questions
What is the minimum number of moves for Tower of Hanoi?
The minimum is 2^n - 1 moves, where n is the number of discs. So 3 discs = 7 moves, 5 discs = 31 moves, 8 discs = 255 moves. It's mathematically proven that no solution can use fewer moves.
Is there a trick to solving Tower of Hanoi?
Yes! Use recursive thinking: to move n discs, first move the top n-1 discs to the spare peg, move the largest disc to the goal, then move the n-1 discs from the spare to the goal. This pattern solves any size.
Why is Tower of Hanoi important in computer science?
It's a classic example of recursion — a problem that solves itself by breaking down into smaller identical sub-problems. It's taught in virtually every introductory computer science course worldwide.