A Robot Walk and the Puzzle of Optimal Binary Encoding

How few bits does it take to send directions that occur with unequal frequencies?

Channel
3Blue1Brown
Published
Jun 10, 2026
Video
1:02
Read
1 min
Slides
1
Original
English
Open on YouTube
Scroll to read and the video shrinks to the bottom-right corner. Captions follow your reading language.
Reading languageAvailable in 2 languages
You're reading the original English.
SUMMARY

In 30 seconds

3Blue1Brown poses a binary-encoding puzzle about a robot on a distant moon. The challenge is to find the most efficient encoding and prove it optimal, an introduction to Shannon entropy; the short does not provide the solution.

  1. 1Four directions, unequal frequenciesThe robot follows a biased random walk: up one half, down one quarter, and left and right one eighth each.
  2. 2Find an efficient codeEncode the instructions in binary while minimizing bits per instruction.
  3. 3Prove optimalityShow that no other encoding can improve on your answer; the video leaves the proof as a challenge.

Takeaways

  1. The robot moves up half the time, down one quarter, and left or right one eighth each.
  2. The first challenge is to encode the instructions in binary using as few bits per instruction as possible.
  3. The second is to prove no other encoding can do better, leading toward Shannon entropy.
FULL TEXT

Read the edited text by chapter

Transcript only
01

A robot on a distant moon

The robot can move in four directions with unequal frequencies.

Imagine I have sent a robot to a far-away moon, and we want to send it movement instructions from Earth. Each instruction is simple: step up, down, left or right.

The instructions make the robot follow a biased random walk. Half its movements are up, one quarter are down, and one eighth each are left and right.

02

The encoding challenge

Find the most efficient binary code and prove that it cannot be beaten.

Unequal probabilities for the four directions
SLIDE 1 / 1Unequal probabilities for the four directionsThe diagram shows the direction frequencies that the encoding must accommodate.

Here is the two-part puzzle. First, find the most efficient way to encode these instructions in binary, using as few bits per instruction as possible. For challenge mode, prove that your answer really is optimal: no other encoding can do better.

03

The connection to entropy

The puzzle is a first step toward Shannon entropy; the linked full video explains further.

If you can answer that, you have taken a first step toward reinventing Shannon entropy. The full video, the first in a series on the phrase “compression is intelligence,” explains the details. This short poses the question without giving the solution.

More from this channel

20 slides40:44EN
3Blue1Brown· Oct 16, 2026Grant Sanderson: There's never been a better time to go into mathGrant Sanderson, Constantin Kogler · 3Blue1BrownStudents fear AI has solved mathematics. Grant Sanderson argues the opposite: even if machines prove theorems better than we do, the institution of math stays valuable—and this is a rare moment when newcomers can reshape it.MathematicsAI for scienceHuman-AI Collaboration+2
29 slides51:55EN
3Blue1Brown· Sep 18, 2026The last IMO problem AI could not solveGrant Sanderson · 3Blue1BrownGrant Sanderson walks through IMO 2025 Problem 6 — a tiling puzzle that frontier models missed — and the visual patience it takes to prove a construction is optimal.MathematicsAI researchReasoning & test-time compute+2
0:55EN
3Blue1Brown· Jul 24, 2026The 64 Sugar Cubes Puzzle: Six Equal DistancesA 4×4×4 block has three colors; prove that six same-colored pairs share a distance.MathematicsEducation
Slides2:25EN
3Blue1Brown· Jun 12, 2026How Shannon Measured the Entropy of EnglishA guessing game helped Claude Shannon estimate how much information English text contains, and why prediction is central to compression.MathematicsAI History
4 slides32:19EN
3Blue1Brown· Jun 7, 2026Reinventing Entropy: Why Prediction Helps Compress LanguageA robot’s movement code leads from prefix-free encoding to Shannon information and the entropy of language.MathematicsScience Communication
0:48EN
3Blue1Brown· Mar 25, 2026The Subset Sum Puzzle: Who Has a Winning Strategy?Choose ten integers from 1 to 100, then look for two different subsets with the same sum.MathematicsEducation