← whatifs.fun
🗼

Tower of Hanoi

Move all discs from the first peg to the last

Difficulty
Moves
0
Minimum
7
Efficiency
100%
Time
0:00
5x
🎉
Puzzle Complete!
You solved it!
Discs
3
Your Moves
7
Minimum
7
Efficiency
100%
Time
0:00

Press Enter to play again

What Is Tower of Hanoi?

The Tower of Hanoi is a classic mathematical puzzle invented by French mathematician Edouard Lucas in 1883. It consists of three pegs and a set of graduated discs that can slide onto any peg. The puzzle begins with all discs stacked on the first peg in order of size, largest on the bottom. The goal is to move the entire stack to the last peg, obeying two rules: move only one disc at a time, and never place a larger disc on top of a smaller one.

How It Works

The elegant recursive solution breaks the problem into three steps: move the top n−1 discs to the spare peg, move the largest disc to the target peg, then move the n−1 discs from the spare peg to the target. This yields a minimum of 2n−1 moves. The legend says monks are moving 64 golden discs between three diamond needles, and when they finish the world will end — at one move per second that would take roughly 585 billion years, far longer than the current age of the universe.

Frequently Asked Questions

What is the minimum number of moves?

The minimum is 2n−1 where n is the number of discs. So 3 discs need 7 moves, 4 discs need 15, 5 discs need 31, and so on. This formula comes directly from the recursive structure of the solution and has been proven to be optimal.

How do you solve Tower of Hanoi?

The simplest approach: on odd-numbered turns, move the smallest disc one peg to the right (wrapping around). On even-numbered turns, make the only legal move that does not involve the smallest disc. This iterative method always produces the optimal solution.

Is there a pattern to the solution?

Yes — each disc moves in a predictable cycle. The smallest disc moves every other turn in one consistent direction. Larger discs move less frequently, each appearing at exponentially spaced intervals. This fractal-like pattern makes the solution beautiful and predictable once you see it.