Skip to content
Vamshi Jandhyala

Books · The Fiddler: Solutions

Chapter 15

Can You or “Cantor” You Find the Distance?

Start with the number line from 00 to 11 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)

The first six stages of the Cantor set: each segment loses its middle third at every step.

Solution

The set is self-similar: its left third (in [0,13][0,\tfrac13]) and right third (in [23,1][\tfrac23,1]) are each a copy scaled by 13\tfrac13. A random point lands in the left or right third with probability 12\tfrac12 each, so for two independent points X,YX, Y there are two cases. With probability 12\tfrac12 both fall in the same third; their separation is then 13\tfrac13 of a fresh copy, contributing 1213L\tfrac12\cdot\tfrac13 L to the mean distance L=EXYL = E|X-Y|. With probability 12\tfrac12 they fall in opposite thirds; their gap is 23\tfrac23 plus a difference of two independent copies whose expectation is 00, contributing 1223\tfrac12\cdot\tfrac23. Hence L=1213L+1223=16L+13    L=25.L = \tfrac12\cdot\tfrac13 L + \tfrac12\cdot\tfrac23 = \tfrac16 L + \tfrac13 \;\Longrightarrow\; L = \boxed{\tfrac25}.

The computation

Sample Cantor points directly: at each of many ternary places independently choose digit 00 or 22 (never 11, 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 13q1 - 3q, where q=P(X1X2+X3)q = P(X_1 \ge X_2 + X_3). The same self-similarity pins down qq. Writing Xi=13(Xi+ai)X_i = \tfrac13(X_i' + a_i) with ai{0,2}a_i \in \{0, 2\} selecting the third, the difference W=X1X2X3=13(W+A)W = X_1 - X_2 - X_3 = \tfrac13(W' + A), where A=a1a2a3A = a_1 - a_2 - a_3 takes the values 2,0,2,42, 0, -2, -4 with probabilities 18,38,38,18\tfrac18, \tfrac38, \tfrac38, \tfrac18. Working through the cases, q=181+38q+380+180    q=15,q = \tfrac18\cdot 1 + \tfrac38\, q + \tfrac38\cdot 0 + \tfrac18\cdot 0 \;\Longrightarrow\; q = \tfrac15 , so the triangle probability is 1315=251 - 3\cdot\tfrac15 = \boxed{\tfrac25}, the same 25\tfrac25 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 qq), 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