Tower of Hanoi online

In the Tower of Hanoi you move every disc from one peg to the target peg, one disc per move and never a larger disc onto a smaller one. Choose 3 to 10 discs; with n discs you need at least 2ⁿ − 1 moves. The hint shows the next move of a shortest solution. No sign-up, works on phones.

Source: Wikipedia: Tower of Hanoi (Regeln, 2ⁿ − 1 Züge, Lösungsalgorithmus). Updated: .

Move all discs to peg 3 (★). Tap the peg you take from, then the peg you put the disc on.

Moves: 0 Minimum: 15

Rules: all discs must end up on the peg with the star. Each move shifts only the top disc of a peg, and a larger disc may never lie on a smaller one.

Controls: tap a peg, then tap the target peg. On a keyboard the keys 1, 2 and 3 pick the peg and the arrow keys move the focus.

My Toolbox

Result

How it is calculated

In short: The Tower of Hanoi is a puzzle with three pegs and a stack of discs of different sizes. You move the whole stack to another peg without ever placing a larger disc on a smaller one. With n discs the fastest solution takes 2ⁿ − 1 moves.

The rules

  1. Move exactly one disc per turn, and only the top disc of a peg.
  2. Place it on an empty peg or on a larger disc.
  3. At the end all discs sit in their original order on the target peg (peg 3, marked with a star).

How many moves are needed at least?

DiscsMinimum moves
37
415
531
663
7127
101,023

Every extra disc doubles the moves and adds one: 2ⁿ − 1. The formula comes from the method: first move the upper n − 1 discs to the spare peg, then the largest disc to the target, then the n − 1 discs back on top of it.

Step-by-step strategy

The smallest disc moves on every second turn. With an even number of discs move it 1 → 2 → 3 → 1, with an odd number 1 → 3 → 2 → 1. On the turns in between there is exactly one legal move that does not involve the smallest disc – make it. The “Hint” button shows the next move of a shortest solution, “Play best move” plays it for you.

Puzzle series

“Next puzzle” walks you through a series: no. 1 to 7 are standard towers with 3 to 9 discs; from no. 8 on every puzzle starts from a different legal position with a changing target peg. Your progress stays on your device only.

Frequently asked questions

How many moves does the Tower of Hanoi need?

With n discs at least 2ⁿ − 1 moves: 7 for 3 discs, 15 for 4, 31 for 5, 1,023 for 10. It is proven that fewer is impossible.

How do I get started?

Move the smallest disc on every second turn: with an even number of discs first to peg 2, with an odd number first to peg 3. In between, make the only other legal move.

What if I made a wrong move?

The hint works out the next move of a shortest path to the goal from any position. “Undo” takes back your last move.

Where does the puzzle come from?

The French mathematician Édouard Lucas invented it in 1883. The legend of the monks with 64 golden discs was part of the original box.

Is my progress saved?

Only which puzzle numbers you solved, and only in your browser (localStorage). Nothing is sent anywhere.

Sources and legal basis

As of: · Editorial policy

Related tools