Books · The Fiddler: Solutions
Chapter 15
Can You or “Cantor” You Find the Distance?
Start with the number line from to and remove the open middle third. Remove the middle third of each remaining piece, and repeat forever; what survives is the Cantor set. Pick two points independently at random in the Cantor set, each chosen by going left or right with equal probability at every step. On average, how far apart are they?
The Fiddler, Zach Wissner-Gross, March 13, 2026(original post)
Solution
The set is self-similar: its left third (in ) and right third (in ) are each a copy scaled by . A random point lands in the left or right third with probability each, so for two independent points there are two cases. With probability both fall in the same third; their separation is then of a fresh copy, contributing to the mean distance . With probability they fall in opposite thirds; their gap is plus a difference of two independent copies whose expectation is , contributing . Hence
The computation
Sample Cantor points directly: at each of many ternary places independently choose digit or (never , the removed middle), build the values, and average the distance between two independent draws.
import numpy as np
rng = np.random.default_rng(0)
def cantor(n, K=40): # n points, K ternary digits
b = rng.integers(0, 2, size=(n, K)).astype(float)
return b @ (2.0 / 3.0**np.arange(1, K + 1))
X, Y = cantor(8_000_000), cantor(8_000_000)
print(round(np.mean(np.abs(X - Y)), 4)) # ~0.4
Extra Credit
Now pick three points independently in the Cantor set. What is the probability that the three values can be the side lengths of a triangle?
Solution
Three lengths form a triangle exactly when the largest is at most the sum of the other two, so the only way to fail is for one value to be at least the sum of the other two. Those three failure events are disjoint, so the triangle probability is , where . The same self-similarity pins down . Writing with selecting the third, the difference , where takes the values with probabilities . Working through the cases, so the triangle probability is , the same as the main answer. (The source’s extra-credit value is behind its paywall; this exact result is my own.)
The computation
Sample three Cantor points the same way and measure two things: how often one exceeds the sum of the other two (the failure rate ), and how often the three actually form a triangle.
rng = np.random.default_rng(1)
def cantor(n, K=45):
b = rng.integers(0, 2, size=(n, K)).astype(float)
return b @ (2.0 / 3.0**np.arange(1, K + 1))
a, b, c = (cantor(10_000_000) for _ in range(3))
m = np.maximum.reduce([a, b, c])
print(round(np.mean(a >= b + c), 4), # ~0.2 -> q = 1/5
round(np.mean(m <= a + b + c - m), 4)) # ~0.4 -> 2/5