Main menuGallery

Tower of Hanoi

This exhibit needs WebGL, which your browser or device has turned off.
Try a different browser, or enable hardware acceleration, to see the Tower of Hanoi.

Tower of Hanoi

Moves0
Minimum 2n−131
Time0:00
move all to peg C
Drag the top disc onto another peg — or tap a peg, then tap its destination (keys 1 / 2 / 3 work too). Drag the background to orbit, scroll to zoom.

Recursion & binary

Call tree — remaining work

Binary counter

What's the maths?

Where's the maths? This puzzle is a machine for discovering recursion: solving a problem by first solving a smaller copy of itself. Writing that down gives a recurrence relation — a rule for the number of moves in terms of the number for one fewer disc — and solving the recurrence gives a formula with a power of 2 in it. Hidden inside one wooden toy are exponential growth, binary numbers, and proof by induction: the way you show a formula is right not just for 5 discs but for every possible number of discs.

📘 On the Sec 1–4 syllabus
  • Sec 1 · N5 Algebraic expressions — 5.5 recognising and representing patterns by finding an algebraic expression for the nth term
  • Sec 3/4 · N1 Numbers — 1.9 positive, negative, zero and fractional indices; 1.10 laws of indices
  • Sec 3/4 · N6 Functions and graphs — 6.10 graphs of exponential functions y = kaˣ

Beyond the syllabus: recurrence relations and proof by induction are beyond O-Level.

To move n discs from one peg to another you must first move the top n−1 discs out of the way, shift the big disc, then move those n−1 discs back on top. So the puzzle solves itself — it just needs a smaller copy of itself twice.

That gives the recurrence T(n) = 2·T(n−1) + 1, with T(1) = 1, and unrolling it gives the closed form T(n) = 2n − 1.

  • 5 discs → 31 moves. 8 discs → 255 moves. Each extra disc doubles the work.
  • The legend: 64 golden discs in a temple, one move a second. 264 − 1 seconds is about 585 billion years — the universe is only ~13.8 billion years old.
  • Number the moves 1, 2, 3, … In the shortest solution, move k always shifts the disc given by the number of trailing zeros in k written in binary, plus one. Move 4 = 100₂ has two trailing zeros, so it moves disc 3. Watch the counter.
  • Draw every legal position of a 3-disc puzzle as a dot and join positions one move apart: you get the Sierpiński triangle. The shortest solution is one side of it.
Try this: set 3 discs and count the moves by hand (you should need 7). Now predict 4 discs before pressing Solve — did 2·7 + 1 = 15 come out right?