Binary, Hanoi, and Sierpinski, part 2
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 can be translated into Towers of Hanoi moves by using which trailing bits flip at each increment.
Briefing
Towers of Hanoi can be solved—efficiently and legally—by counting upward in binary and using the “bit-flip rhythm” to decide which disk moves. The key insight is that each rollover in binary corresponds to freeing a specific disk: flipping only the last bit moves disk 0, flipping the last two bits moves disk 1, and so on. That mapping turns a classic recursive puzzle into a simple counting procedure, turning what looks like combinatorics into a pattern you can “read” off the sequence 0, 1, 10, 11, 100, 101, …
The explanation starts with a quick reframing of binary as a self-similar counting process. In base 10, digits roll over after reaching 9; in base 2, digits roll over constantly because only 0 and 1 exist. Counting in binary has a repeating structure at every scale: do something, roll over, do the same thing again—except the “something” happens on the least significant bits, then on larger blocks as the count grows. For example, moving from 01 to 10 flips the last bit and forces a rollover; moving from 011 to 100 flips a larger block of bits, and the same hierarchical rollover pattern continues at powers of two.
Keith Schwartz’s Hanoi rule uses that hierarchy directly. Begin counting from 0. Each time the binary count flips only the last bit (0→1), move disk 0 one peg to the right, looping back to the first peg if needed. When the count rolls over to the “twos place,” meaning the last two bits flip, move disk 1 to the only legal peg available—because disk 0 blocks one peg and the rules forbid placing a larger disk on top of a smaller one. The same logic scales: rollovers to the fours place move disk 2, rollovers to the eights place move disk 3, and so on. The surprising part isn’t just that the moves work; it’s that the sequence is automatically optimal.
That optimality comes from a recursive perspective on the puzzle. To move disk k, all smaller disks must be cleared off it, disk k moves exactly once to the target peg, and then the smaller disks must be moved back onto it. Every disk follows the same strategy: “everyone above me, get off; I move; everyone pile back on.” This structure matches binary counting’s self-similarity: counting up to a power of two repeats the same subpattern, then performs a rollover that corresponds to the single “move the big disk” moment. In the smallest cases, the match is explicit—two-disk Hanoi (move 0, move 1, move 0) mirrors the bit pattern changes in counting up to 3. At larger scales, the recursive decomposition of Hanoi aligns with the recursive decomposition of binary.
The result is a clean conceptual bridge: binary’s bit flips can be viewed as a reverse-engineering of the recursive Hanoi algorithm. And the payoff is promised to go further—this same fractal, self-similar logic is set up to connect to generating a curve that fills Sierpinski’s triangle in the next installment.
Cornell Notes
Binary counting provides a direct, rule-based way to execute the Towers of Hanoi moves. Each disk corresponds to a level of binary significance: disk 0 moves whenever only the last bit flips; disk 1 moves when the last two bits flip during a rollover; disk 2 moves on rollovers affecting the last three bits, and so on. The legality of each move comes from constraints—smaller disks block some pegs and forbid placing larger disks on top of them—so the “forced” destination is determined automatically. The efficiency is explained by recursion: moving disk k requires clearing disks 0..k−1, moving disk k once, then restoring disks 0..k−1. Binary’s self-similar rollover pattern mirrors that exact subproblem-then-single-move-then-subproblem structure.
How does a binary rollover determine which Hanoi disk moves?
Why is the move always legal, even though the rule seems to “jump” disks at rollovers?
What makes the binary method optimal rather than just correct?
How does the “self-similarity” of binary counting match the recursion of Hanoi?
Can the smallest example show the correspondence concretely?
Review Questions
- When counting in binary, what specific condition tells you to move disk 1 rather than disk 0?
- Explain the recursive strategy for moving disk k in Towers of Hanoi and relate each stage to a corresponding part of the binary counting pattern.
- Why does the “forced destination” rule (only one legal peg) matter for the correctness of the binary-to-Hanoi mapping?
Key Points
- 1
Binary counting can be translated into Towers of Hanoi moves by using which trailing bits flip at each increment.
- 2
Flipping only the last bit moves disk 0 one peg to the right, with wraparound from the last peg to the first.
- 3
A rollover that flips the last two bits moves disk 1, and the destination is forced by the current positions of smaller disks.
- 4
The method scales: rollovers affecting larger trailing-bit blocks correspond to moving higher-numbered disks.
- 5
Optimality follows from recursion: moving disk k requires clearing disks 0..k−1, moving disk k once, then restoring disks 0..k−1—steps that any solution must include.
- 6
Binary counting and Hanoi share the same self-similar structure: subproblem, single “big move,” subproblem at every scale.