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

Binary, Hanoi, and Sierpinski, part 2

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 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?

The mapping is based on which bits change when the count advances. Flipping only the last bit (0→1) moves disk 0 one peg to the right (wrapping from the rightmost peg back to the first). When the count rolls over so that the last two bits flip, disk 1 moves; the destination is forced because disk 0 occupies one peg and the rules forbid placing disk 1 on top of disk 0. The same pattern continues: rollovers that affect larger blocks of trailing bits correspond to moving disk 2, disk 3, etc.

Why is the move always legal, even though the rule seems to “jump” disks at rollovers?

Legality follows from the blocking structure of the puzzle. Before disk k can move, all smaller disks (0 through k−1) must be off disk k’s current peg. The binary rule’s rollover timing ensures that exactly at the moment disk k’s “turn” arrives, those smaller disks have been arranged so disk k is free. When disk k moves, only one peg is available that does not violate the “no larger-on-smaller” rule, so the destination is determined by what smaller disks currently occupy.

What makes the binary method optimal rather than just correct?

The recursive structure of Hanoi leaves no slack. To move disk k, the process must (1) move disks 0..k−1 away, (2) move disk k once, and (3) move disks 0..k−1 onto the destination. Any solution must perform those forced substeps, so there’s no room for inefficiency. Binary counting mirrors this by repeating the same subpattern at each scale and then performing a single rollover event that corresponds to the one required move of the larger disk.

How does the “self-similarity” of binary counting match the recursion of Hanoi?

Both systems repeat the same structure at increasing scales. In binary, counting up to a larger power of two repeats the smaller counting pattern, then triggers a rollover that flips a larger block of bits. In Hanoi, solving for k disks repeats the solution for k−1 disks, performs the single move of disk k, then repeats the k−1 disk solution again. The alignment is that “subproblem, then one big move, then subproblem” is the same skeleton in both.

Can the smallest example show the correspondence concretely?

Yes. For two disks, the legal sequence is move disk 0, move disk 1, move disk 0. That three-move pattern matches the bit-flip rhythm of counting up to 3 in binary: the last-bit flip happens, then a rollover forces a change involving the next bit, then the last-bit flip happens again. The same idea scales upward: three-disk Hanoi is “solve two disks, move disk 2, solve two disks,” paralleling how counting up to 7 (111 in binary) repeats the smaller pattern around a rollover.

Review Questions

  1. When counting in binary, what specific condition tells you to move disk 1 rather than disk 0?
  2. 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.
  3. Why does the “forced destination” rule (only one legal peg) matter for the correctness of the binary-to-Hanoi mapping?

Key Points

  1. 1

    Binary counting can be translated into Towers of Hanoi moves by using which trailing bits flip at each increment.

  2. 2

    Flipping only the last bit moves disk 0 one peg to the right, with wraparound from the last peg to the first.

  3. 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. 4

    The method scales: rollovers affecting larger trailing-bit blocks correspond to moving higher-numbered disks.

  5. 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. 6

    Binary counting and Hanoi share the same self-similar structure: subproblem, single “big move,” subproblem at every scale.

Highlights

Disk moves line up with binary bit-flips: disk 0 moves on last-bit flips; disk 1 moves on rollovers that flip the last two bits; higher disks follow the same hierarchy.
The binary method isn’t just a clever trick—it matches the recursive, forced structure of Hanoi, which is why it achieves the puzzle’s efficiency.
Self-similarity is the bridge: both binary counting and Hanoi solutions repeat the same pattern at larger powers of two / larger disk counts.

Topics

  • Towers of Hanoi
  • Binary Counting
  • Recursive Algorithms
  • Self-Similarity
  • Sierpinski Triangle

Mentioned

  • Keith Schwartz