Fifty Strings in a Box
A MoMath Monthly Mindbender: fifty strings have their loose ends tied at random until none remain. The expected number of loops is 1 + 1/3 + 1/5 + ... + 1/99 = 2.938, a shade under three. Since that sum is H(2n) - H(n)/2, the count grows only like half a logarithm, so even a thousand strings average fewer than five loops.
Problem
To keep your visiting five-year-old niece busy, you mix 50 strings of orange yarn in a box and ask her to successively grab two random ends and tie them together until there are no loose ends remaining. The result will of course be some number of loops of string. How many, on average?
Credit: Peter Winkler, Monthly Mindbenders, National Museum of Mathematics, May 2026, a variation of a classic.
One tie at a time
Write for the expected number of loops made from strings. A box of strings holds loose ends, every tie consumes two of them, so there are exactly ties and the box always finishes with nothing loose in it.
Look at the first tie. Pick up any end at all; by symmetry it does not matter which one, since nothing has been tied yet and the ends are interchangeable. That end gets joined to one of the other ends, each equally likely. Exactly one of those candidates is the other end of the same piece of string, and that single case behaves quite differently from the rest.
- With probability the end meets its own partner. The string closes into a loop, the loop leaves the box, and it is never touched again. One loop completed, strings remaining.
- With probability the end meets an end belonging to a different string. The two strings become one longer string with two free ends. No loop completed, and again strings remaining.
Both branches leave strings in the box, each with two free ends. Nothing about what happens next depends on how long any of those strings is, or on which ties produced it, so the process simply restarts on strings and the expected number of loops still to come is either way. Conditioning on the first tie,
That self-similarity is the whole of the argument, and it is also why the answer is a plain sum of reciprocals rather than something more intricate. The state of the box is captured by a single number, the count of strings, and each tie reduces that count by one at a cost depending on nothing else.
With the recursion telescopes:
For the niece’s box of fifty,
a shade under three loops from fifty strings and fifty ties.
The same sum without induction
Linearity of expectation reaches the answer in one line, and the counting is worth seeing on its own. Number the ties by the state they act on: some tie takes the box from strings down to strings, for each from down to . At that tie the box holds ends, the chosen end has possible partners, and exactly one of them closes a loop. Let be the indicator of that event, so .
Every loop is closed by exactly one tie, so the total number of loops is . Expectation adds regardless of dependence:
The logarithmic crawl
Sums of odd reciprocals reduce to harmonic numbers. The even terms are , so removing them from leaves the odd ones:
Substituting ,
with constant . At fifty the approximation returns against the exact , an error in the sixth decimal place.
Half a logarithm is very slow growth, and that is the part worth sitting with. Doubling the number of strings adds to the expected count, so each additional loop costs roughly a sevenfold increase in yarn. A thousand strings average loops. A box would need something like a hundred thousand strings before the expected count reached seven.
| 1 | 2 | 5 | 10 | 50 | 100 | 1000 | |
|---|---|---|---|---|---|---|---|
The whole distribution, not just the mean
One further remark comes free. The indicators are independent, because the conditional probability never depended on what the earlier ties did. So the number of loops is a sum of independent coin flips with success probabilities , and convolving them gives the exact distribution.
| loops | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|
| probability |
Six loops or fewer covers per cent of boxes, and the standard deviation is . The niece is very likely to hand back a small handful, and about one time in eight a single loop of yarn some fifty strings long.
Computational verification
The recursion is short enough to be suspicious of, so the check ignores it and plays the game instead. Shuffle the ends into a random pairing, walk through the pairs, and keep a disjoint-set structure over the strings: if the two ends already belong to the same string then a loop has closed, otherwise the two strings merge into one. Nothing in the simulation knows about .
import numpy as np
L = lambda n: sum(1.0/(2*k-1) for k in range(1, n+1)) # 1 + 1/3 + ... + 1/(2n-1)
G = 0.5772156649015329 # Euler-Mascheroni
asym = lambda n: 0.5*np.log(n) + np.log(2) + G/2
def simulate(n, trials, rng): # shuffle 2n ends, tie in pairs, count loops
total = 0
for _ in range(trials):
parent = list(range(n)) # disjoint set over the strings in the box
def find(x):
while parent[x] != x:
parent[x] = parent[parent[x]]; x = parent[x]
return x
# ends 2i and 2i+1 are the two ends of string i
for a, b in rng.permutation(2*n).reshape(-1, 2):
ra, rb = find(a//2), find(b//2)
if ra == rb: total += 1 # both ends of one string: a loop closes
else: parent[ra] = rb # two strings merge into one longer string
return total/trials
rng = np.random.default_rng(20260516)
print(f"exact L_50 = {L(50):.6f}")
print(f"sim L_50 = {simulate(50, 40_000, rng):.6f} (40,000 trials)")
print(f"asymp L_50 = {asym(50):.6f} ln2 + gamma/2 = {np.log(2)+G/2:.6f}")
for n in (1, 2, 5, 10, 50, 100, 1000):
print(f" n = {n:4d} L_n = {L(n):.6f} asymptotic = {asym(n):.6f}")
# exact L_50 = 2.937775
# sim L_50 = 2.934200 (40,000 trials)
# asymp L_50 = 2.937767 ln2 + gamma/2 = 0.981755
# n = 1 L_n = 1.000000 asymptotic = 0.981755
# n = 2 L_n = 1.333333 asymptotic = 1.328329
# n = 5 L_n = 1.787302 asymptotic = 1.786474
# n = 10 L_n = 2.133256 asymptotic = 2.133048
# n = 50 L_n = 2.937775 asymptotic = 2.937767
# n = 100 L_n = 3.284342 asymptotic = 3.284340
# n = 1000 L_n = 4.435633 asymptotic = 4.435633
Forty thousand simulated boxes give against the exact , a discrepancy of against a standard error of .
The puzzle is usually told with a specific number of strings, and the number invites you to guess. Fifty strings sounds like it should give a decent pile of loops. It gives about three, and ten times as much yarn would give about four and a half.