Test yourself. Challenge friends.
โ†

Tower of Hanoi

๐Ÿ—ผ
Tower of Hanoi

Move all discs from the first peg to the last peg. You can only move one disc at a time, and a larger disc can never go on top of a smaller one.

Choose number of discs:
FAQ
What is the Tower of Hanoi?

The Tower of Hanoi is a mathematical puzzle with discs stacked by size on one peg. Move all discs to another peg, one at a time, never placing a larger disc on a smaller one.

What is the minimum number of moves?

The minimum moves for n discs is 2^n - 1. So 3 discs needs 7 moves, 5 discs needs 31, and 7 discs needs 127. The puzzle grows exponentially harder.

Who invented it?

French mathematician Edouard Lucas invented the puzzle in 1883. He created a legend about monks moving 64 golden discs, claiming the world would end when they finished (it would take 585 billion years).

About this test

The Tower of Hanoi is a classic mathematical puzzle invented in 1883. It demonstrates exponential growth and recursive problem-solving in a tangible, satisfying way.

How It Works

Move a stack of discs from the starting peg to the target peg. You can only move one disc at a time, and no disc may be placed on top of a smaller disc. Solve it in the minimum number of moves.

The Algorithm

The solution is inherently recursive: to move n discs, first move n-1 discs to the spare peg, move the bottom disc to the target, then move n-1 discs from the spare to the target.

Tips

  • Always move the smallest disc to the next peg in a consistent direction
  • The minimum solution alternates between moving the smallest disc and making the only other legal move
  • Start with 3 discs to learn the pattern