Skip to content
Vamshi Jandhyala

Books · The Fiddler: Solutions

Chapter 53

How Long Is the River?

In the language Fiddlish every word is three or four letters long (each equally likely), and words are separated by single spaces. Deep into a long line of text, what is the probability that a given character is a space?

The Fiddler, Zach Wissner-Gross, May 23, 2025(original post)

Solution

Each word contributes, on average, 3.53.5 letters plus its one trailing space: 4.54.5 characters per word, exactly one of them a space. By the renewal theorem the long-run fraction of spaces is 14.5=2922.2%.\frac{1}{4.5}=\boxed{\frac29}\approx22.2\%.

The computation

Generate the actual stream: draw millions of words of three or four letters, append one space to each, and take the fraction of all characters that are spaces.

import numpy as np
rng = np.random.default_rng(0)
words = rng.integers(3, 5, 5_000_000)        # 3 or 4 letters, equally likely
spaces = len(words); total = int((words + 1).sum())   # +1 space per word
print(round(spaces / total, 4))              # 0.2222  = 2/9

Extra Credit

In a monospace font, suppose the 1212th character of a line is a space. A “river” runs diagonally down and to the right: line 22 continues it if its 1313th character is a space, line 33 if its 1414th is a space, and so on. How long is the river on average?

Solution

Different lines are independent, so the river continues to each next line with the probability that that line has a space at the relevant position. Crucially those positions (13,14,15,13,14,15,\dots) are near the start of the line, where the space probability has not yet settled to 29\tfrac29. Writing uqu_q for the renewal probability of a space at position qq (steps of 44 or 55, each 12\tfrac12), E[length]=1+m1j=1312+muj1.535.\mathbb{E}[\text{length}]=1+\sum_{m\ge1}\prod_{j=13}^{12+m}u_j\approx\boxed{1.535}. (The source’s value is paywalled; this is my own, with u13=u14=38u_{13}=u_{14}=\tfrac38 well above 29\tfrac29.)

The computation

Build the renewal probability uqu_q that position qq is a space (each space sits 44 or 55 characters past the previous, equally likely), then accumulate the river’s expected length as the running product of continuation probabilities from position 1313 on.

from fractions import Fraction as F
u = [F(0)] * 160; u[0] = F(1)
for q in range(1, 160):
    u[q] = (u[q - 4] if q >= 4 else 0) / 2 + (u[q - 5] if q >= 5 else 0) / 2
E = F(1); prod = F(1)
for j in range(13, 160): prod *= u[j]; E += prod
print(float(E))                          # 1.5347