Binary, Hanoi and Sierpinski, part 1
Based on 3Blue1Brown's video on YouTube. If you like this content, support the original creators by watching, liking and subscribing to their content.
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?
Why is the move sequence guaranteed to be legal, especially when larger disks are supposed to move at rollovers?
What recursive viewpoint makes the binary mapping feel inevitable?
How does the self-similarity show up in small examples like 2 or 3 disks?
Why does this method achieve the most efficient solution?
Review Questions
- Can you describe the rule for moving disk 0 and disk 1 in terms of which bits flip during binary counting?
- 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.
- 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
Binary counting’s carry/rollover structure maps directly to which Hanoi disk must move next.
- 2
Flipping only the last bit moves disk 0 one peg to the right (wrapping around if it reaches the end).
- 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
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
Optimality follows from forced legality: clearing smaller disks and restoring them leaves no room for inefficiency.
- 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.