Tower of Hanoi
Three pegs, a stack of disks, and one constraint: you can never put a bigger disk on top of a smaller one. Move the entire stack from the left peg to the right peg, one disk at a time. It sounds like a five-minute diversion until you try it with seven disks and realize you're 80 moves in with no end in sight.
Tower of Hanoi
3 disks — A quick warm-up. 7 moves to solve if you move perfectly.
Standard play. Timer runs. Hints available.
What is the Tower of Hanoi?
The Tower of Hanoi was invented by French mathematician Edouard Lucas in 1883. He sold it as a toy under the name “Professor Claus” — an anagram of his own surname. The puzzle has three pegs and a set of disks in graduated sizes, all stacked on the first peg with the largest at the bottom. Your task: move the entire stack to the third peg, moving only one disk at a time, and never placing a larger disk on a smaller one.
The puzzle shows up everywhere: math classrooms, computer science courses, psychology experiments on problem-solving, and cognitive assessment batteries. It has a clean mathematical structure (the minimum solution is always 2n - 1 moves for n disks) and an elegant recursive solution that makes it a standard introduction to recursion in programming.
Rules
- One disk at a time. Pick up the top disk from any peg and place it on top of another peg.
- No larger on smaller. A disk can only go onto an empty peg or on top of a disk that's bigger than it.
- Move everything to the target peg. Start with all disks on the left peg, finish with all disks on the right peg.
That's the whole thing. Three rules, no arithmetic, no hidden constraints. The difficulty comes purely from the number of disks. For a deeper walkthrough, read the full rules & strategy guide.
The legend of Brahma
Lucas published the puzzle with a fictional backstory that stuck. According to the legend, in a temple near Varanasi, Brahmin monks have been moving 64 golden disks between three diamond pegs since the creation of the world. They follow the same rules: one disk at a time, never larger on smaller. When they complete the task, the world ends.
The math behind the legend is real. Moving 64 disks optimally takes 264 - 1 moves — that's 18,446,744,073,709,551,615 moves. At one move per second, it would take roughly 585 billion years. The current age of the universe is about 13.8 billion years. So either the monks are very patient, or the world is safe for a while.
Strategy tips
The recursive approach is the most common: to move n disks from source to target, first move the top n-1 disks to the spare peg, move the largest disk directly to the target, then move the n-1 disks from the spare peg onto the target. This breaks a seemingly complex problem into smaller copies of itself.
If recursive thinking isn't your thing, there's a mechanical shortcut. On odd-numbered moves, always move the smallest disk. On even-numbered moves, make the only legal move that doesn't involve the smallest disk. Follow this pattern and you'll hit the optimal solution every time without needing to think recursively.
For 3 disks, the direction pattern for the smallest disk is: right, left, right, left. For 4 or more, it alternates depending on whether the disk count is odd or even. With an odd number of disks, the smallest disk cycles right (source → target → auxiliary → source). With an even number, it cycles left (source → auxiliary → target → source).
Difficulty levels
| Level | Disks | Optimal | What to expect |
|---|---|---|---|
| Easy | 3 disks | 7 moves | A quick warm-up. 7 moves to solve if you move perfectly. |
| Medium | 4 disks | 15 moves | 15 optimal moves. You need to plan a couple of steps ahead. |
| Hard | 5 disks | 31 moves | 31 moves minimum. Recursive thinking starts to pay off here. |
| Expert | 7 disks | 127 moves | 127 moves. You need patience and a clear mental model of the recursive pattern. |
| Einstein | 10 disks | 1,023 moves | 1,023 moves of pure focus. The pattern is the same — the endurance is the challenge. |
How to play
- Click/tap a peg to select the top disk, then click/tap the destination peg to move it.
- Keyboard: press 1, 2, or 3 to select a peg, then 1, 2, or 3 again for the destination. Arrow keys also work.
- Undo if you make a wrong move (Ctrl+Z or the undo button).
- Hints give progressive help: first a sub-goal, then a pattern tip, then the exact next move.
- Auto-solver animates the optimal solution, one move at a time. Useful for studying the recursive pattern.
Three play modes: Classic (no time pressure), Timed Trial (beat the clock), and Challenge (no hints, no undo).
Frequently asked questions
What is the Tower of Hanoi?
A mathematical puzzle from 1883. Move a stack of graduated disks from one peg to another, one at a time, without placing a larger disk on a smaller one.
What is the minimum number of moves?
2n - 1, where n is the number of disks. Three disks take 7 moves, five disks take 31, ten disks take 1,023.
What is the Tower of Brahma legend?
A fictional story published with the original puzzle. Monks move 64 golden disks between diamond pegs. When they finish, the world ends. At one move per second, it would take about 585 billion years.
Is there a pattern to solving Tower of Hanoi?
Yes. On odd-numbered moves, move the smallest disk. On even-numbered moves, make the only legal move that doesn't involve the smallest disk. This gives you the optimal solution every time.
Why is Tower of Hanoi used in computer science?
The optimal solution is naturally recursive: solve a smaller version of the same problem, move one disk, solve the smaller version again. This makes it a textbook example of recursion, divide-and-conquer algorithms, and mathematical induction.
Related puzzles
If you like thinking through Tower of Hanoi, try these:
Math Riddles
Logic and number puzzles that test mathematical reasoning.
Brain Teasers
Short puzzles that need lateral thinking and creative problem-solving.
Sudoku
Fill every row, column, and box with 1-9. The most popular logic puzzle in the world.
Mazes
Navigate from start to finish through branching passages. Another spatial reasoning challenge.