Get AI summaries of any video or article — Sign up free
Binary, Hanoi and Sierpinski, part 1 thumbnail

Binary, Hanoi and Sierpinski, part 1

3Blue1Brown·
5 min read

Based on 3Blue1Brown's video on YouTube. If you like this content, support the original creators by watching, liking and subscribing to their content.

TL;DR

Binary counting’s carry/rollover structure maps directly to which Hanoi disk must move next.

Briefing

Towers of Hanoi can be solved—efficiently and with perfect legality—by following the rhythm of binary counting: each “rollover” in base-2 tells which disk must move next. The key insight is that binary’s self-similar carry pattern (“flip the last bit, then roll over; flip the last two bits, then roll over; and so on”) mirrors the recursive structure of the optimal Hanoi strategy, where smaller sub-towers must be rearranged before a larger disk can move.

In the puzzle, three pegs hold a stack of disks labeled by size, with the largest at the bottom. Only one disk moves at a time, and no larger disk may land on a smaller one. With disks numbered 0 (smallest) upward, the first move is forced: disk 0 must move because every other disk has disk 0 or other smaller disks on top. After that, legality keeps narrowing choices until each move becomes determined by what’s currently exposed.

Binary counting supplies that exposure schedule. Start at 0 and count upward in base-2. Every time the counting process flips only the last bit (from 0 to 1), disk 0 moves one peg to the right, looping back to the first peg if needed. When the count rolls over into the “twos place”—meaning the last two bits change via a carry—disk 1 moves, but only to the peg it is forced to occupy: it cannot land on disk 0, and there is only one other legal destination. The same rule scales up: each rollover to the 4s place moves disk 2, rollover to the 8s place moves disk 3, and so on. The surprising part isn’t just that the mapping produces a sequence of moves; it produces the exact disk that becomes free at the right moment.

At first glance, the method raises a legitimacy question: why does a rollover to (say) the 8s place guarantee that disk 3 is actually unblocked? The answer comes from a recursive perspective on Hanoi. To move disk k, all smaller disks (0 through k−1) must be cleared off it, disk k moves once, and then the smaller disks must be rebuilt on top in the new configuration. Each disk follows the same pattern: “everyone above me, get off; I move; everyone pile back on.” That structure is mirrored by binary counting’s repeated cycle of “do a smaller task, roll over, do the same smaller task again,” at every power-of-two scale.

This parallel also explains optimality. The recursive Hanoi strategy is forced at every stage: before disk k can move, the smaller disks must be in exactly the arrangement that makes disk k exposed; after disk k moves, the smaller disks must be restored. There’s no slack for shortcuts, so the binary-driven schedule inherits the minimal number of moves.

The method’s deeper payoff arrives next: the same self-similar logic that links binary carries to recursive disk moves also connects to generating a curve that fills Sierpinski’s triangle, setting up a bridge from counting and recursion to fractal geometry in the follow-on installment.

Cornell Notes

Binary counting provides a direct, disk-by-disk rule for solving Towers of Hanoi. Each time the binary counter changes in a way that corresponds to a rollover at a given power of 2, the matching disk (0 for the last-bit flips, 1 for twos-place rollovers, 2 for fours-place rollovers, etc.) makes its forced legal move. The mapping works because both processes are self-similar: Hanoi clears smaller disks, moves one larger disk once, then rebuilds the smaller stack—exactly like binary repeatedly performs a smaller counting task, rolls over, and performs it again. This correspondence also explains why the approach is optimal: every move is forced by legality and the recursive subproblem structure.

How does a “rollover” in binary determine which Hanoi disk moves?

Disk choice tracks the position of the carry. Flipping only the last bit (0→1) moves disk 0 one peg to the right (wrapping around). When counting rolls over into the twos place—so the last two bits undergo the carry pattern—disk 1 moves to the only legal peg available (it can’t land on disk 0, and there’s just one other destination). The same logic scales: rollover into the fours place moves disk 2, rollover into the eights place moves disk 3, and so on.

Why is the move sequence guaranteed to be legal, especially when larger disks are supposed to move at rollovers?

Legality hinges on exposure. To move disk k, every smaller disk (0 through k−1) must be off disk k. The recursive Hanoi strategy enforces that: solve the subproblem to clear disks 0..k−1, move disk k once, then solve the subproblem again to place disks 0..k−1 back. Binary counting’s carry pattern performs the same “clear smaller part → rollover event → rebuild smaller part” structure, so at each rollover to the 2^k place, disk k is precisely the disk that has been cleared.

What recursive viewpoint makes the binary mapping feel inevitable?

From disk k’s perspective, it can’t move while any smaller disk sits on top of it, and it can’t move onto a peg that currently holds those smaller disks. So the only workable plan is: (1) get disks 0..k−1 off disk k (a smaller Hanoi problem), (2) move disk k to its destination, and (3) bring disks 0..k−1 onto disk k again (another smaller Hanoi problem). Binary counting repeats the same skeleton at every scale: count a smaller range, roll over, then repeat the smaller range.

How does the self-similarity show up in small examples like 2 or 3 disks?

For 2 disks, the optimal move pattern is disk 0, disk 1, disk 0. That mirrors counting up to 3 (binary 11): flip the last bit, roll over once, flip the last bit. For 3 disks, the optimal structure is “solve 2 disks, move disk 2, solve 2 disks again.” Counting up to 7 (binary 111) matches the same idea: count up to 3, roll over all three bits, then count up to 3 again.

Why does this method achieve the most efficient solution?

Efficiency comes from forced steps. At any stage, disk k cannot move until disks 0..k−1 are arranged to clear it, and after disk k moves, those smaller disks must be restored in the correct configuration. The recursive strategy leaves no room for detours because legality dictates exactly what must happen before and after each larger-disk move. Since binary counting reproduces that recursive schedule, it inherits the minimal-move property.

Review Questions

  1. Can you describe the rule for moving disk 0 and disk 1 in terms of which bits flip during binary counting?
  2. Explain, using the recursive “clear smaller disks → move one disk → rebuild smaller disks” pattern, why a rollover to the 2^k place corresponds to disk k becoming movable.
  3. What does it mean for both binary counting and Hanoi to be “self-similar,” and how does that self-similarity show up when scaling from 2 disks to 3 disks?

Key Points

  1. 1

    Binary counting’s carry/rollover structure maps directly to which Hanoi disk must move next.

  2. 2

    Flipping only the last bit moves disk 0 one peg to the right (wrapping around if it reaches the end).

  3. 3

    A rollover into the twos place triggers the move of disk 1, which has only one legal destination given disk 0’s position.

  4. 4

    The method works because both Hanoi and binary counting follow the same recursive template: solve a smaller subproblem, perform a single larger action, then solve the smaller subproblem again.

  5. 5

    Optimality follows from forced legality: clearing smaller disks and restoring them leaves no room for inefficiency.

  6. 6

    The disk-by-disk schedule produced by bit flips can be viewed as reverse-engineering the recursive Hanoi algorithm from the pattern of bit changes.

Highlights

Each binary rollover at 2^k corresponds to moving disk k, with disk destinations forced by the current stack legality.
The legality question—why a larger disk is free exactly when its rollover happens—resolves through the recursive structure of Hanoi.
Binary counting and Hanoi both decompose into “subproblem, one key move, subproblem again,” at every power-of-two scale.
The mapping doesn’t just generate a solution; it reproduces the optimal move schedule because every step is forced.

Topics

  • Towers of Hanoi
  • Binary Counting
  • Recursive Algorithms
  • Sierpinski Triangle
  • Fractals

Mentioned

  • Keith Schwartz