The Tower of Hanoi and the Art of Thinking Recursively

August 5, 20266 min readBen Miller

In 1883, a puzzle appeared in French toy shops under the name of a mysterious oriental professor — "N. Claus de Siam, mandarin of the College of Li-Sou-Stian." Both the professor and his college were anagrams. The real inventor was Édouard Lucas of the Lycée Saint-Louis, one of the great number theorists of his century — the man whose method, refined a little, still powers today's hunts for record prime numbers, and whose name lives on the Fibonacci-like Lucas sequence.

The toy was three pegs and a tower of disks, each smaller than the one beneath. Move the whole tower to another peg, one disk at a time, never placing a larger disk on a smaller. To sell it, Lucas attached a legend: in a temple at Benares, priests labor at the same puzzle with 64 disks of pure gold, and when their final disk falls into place, the world will crumble to dust.

The legend was marketing. The mathematics under it is real, enormous, and — this is the part worth your time — solvable by a single idea that will change how you approach every large problem you ever face.

The insight that dissolves the tower

Stare at a ten-disk tower and try to plan the moves and you will drown; the state space is vast and the goal feels far away. Now ask a different question, one almost lazy in its modesty: what has to be true at the moment the biggest disk moves?

The biggest disk can only move when everything above it is gone — the other nine disks stacked, in order, on the spare peg — and its destination is empty. That's it. That one observation splits the impossible task into three:

  1. Move the top nine disks to the spare peg. (Somehow.)
  2. Move the big disk to the goal. (One move, trivial.)
  3. Move those nine disks from the spare onto the big disk. (Somehow, again.)

The "somehows" look like cheating until you notice what they are: the same puzzle, one disk smaller. And moving nine disks decomposes the same way into moving eight, which decomposes into moving seven, all the way down to moving one disk, which is just… a move. The solution is a set of Russian nesting dolls, each containing a smaller copy of itself, ending at a doll so small it is solid.

This is recursion — solving a problem by arranging for smaller instances of itself to be solved — and it is the closest thing computer science has to a superpower. Programmers meet the Tower of Hanoi in their first semester precisely because it is the purest specimen: three lines of code that command a mountain of moves. But the idea predates and outlives programming. It is the mathematician's induction, the general's campaign of battles, the writer's outline of outlines.

Counting to the end of the world

Recursion doesn't just find the solution; it counts it. Call the minimum number of moves for n disks M(n). Our decomposition says M(n) = M(n−1) + 1 + M(n−1) — twice the smaller solution, plus one move for the big disk. Starting from M(1) = 1, the sequence runs 1, 3, 7, 15, 31… always one less than a power of two: M(n) = 2ⁿ − 1. And no cleverness can beat it — the big disk must move at least once, and each such move provably requires the full smaller tower to evacuate and return.

Now the priests. Sixty-four disks means 2⁶⁴ − 1 moves: 18,446,744,073,709,551,615. At one perfect move per second, day and night without error, the tower takes about 585 billion years — more than forty times the age of the universe. Lucas's doomsday legend is thus perfectly safe, and quietly brilliant: it converts an abstract exponential into theology. (The number may look familiar — it's the same 2⁶⁴ − 1 as the fabled grains of wheat doubling across a chessboard. Exponential growth keeps exactly one story and tells it in different costumes.)

Every solver should sit with the contrast: the description of the solution fits on an index card, while the solution itself outlasts stars. Puzzles are where we practice telling those two kinds of size apart.

Your brain on towers

Psychologists adopted Lucas's toy for their own reasons. The Tower of Hanoi — and its cousin the Tower of London, devised by the neuropsychologist Tim Shallice — became standard instruments for measuring planning: the ability to hold a goal, establish subgoals, and tolerate the strange ache of moving away from the target to enable progress toward it. That ache is the puzzle's psychological signature. Early moves often shift disks in what feels like the wrong direction, and studies of patients with frontal-lobe damage show exactly this capacity — organizing detours in service of a distant goal — is what fails when planning machinery is compromised.

Which names the skill precisely. The tower does not test cleverness; it tests the willingness to serve a subgoal that looks like a step backward. Anyone who has cleared a table in order to sort a drawer in order to find a key already owns the concept.

Recursion at the breakfast table

You will likely never need to relocate sixty-four golden disks. You will constantly need the tower's method:

Find the pivot. In any overwhelming task, ask the lazy question: what single event, once possible, breaks this open? (The big disk's one move.) Then let making that event possible become the new task.

Trust the smaller self. The recursive leap — "assume the nine-disk problem handled" — feels like fraud the first time. It isn't. It is division of labor with your own method. Solvers use it on grids daily: resolve this corner as if the row were settled, then settle the row by the same technique one size down.

Respect exponentials on sight. Any process that doubles per step is not a big number; it is a different category of thing. This instinct — bred by 2ⁿ − 1 — is the one that correctly prices chain letters, compound interest, and viral spread.

Lucas died young, in 1891, from a freak accident at a banquet. His primes, his sequences, and his little tower survive him — the toy still sold, the legend still told, the world still, by our calculation, comfortably un-ended. The priests, if they exist, are barely getting started. So are you: that is rather the point of the method. One disk at a time was never the insight. One tower at a time is.

← Back to Blog