Books · Monthly Mindbenders: Solutions
Chapter 5
Fifty Strings in a Box
A counting puzzle from the Monthly Mindbenders.1
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?
Solution
Write for the expected number of loops made from strings. A box of strings holds loose ends, and every tie uses two of them, so there are exactly ties and the process always ends with the box empty of loose ends.
Look at the first tie. Pick up any end at all; by symmetry it does not matter which, since the ends are interchangeable before anything has been tied. That end is 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. Two cases follow.
With probability the end meets its own partner. The string closes into a loop, which leaves the box and is never touched again. One loop has been completed and strings remain.
With probability the end meets an end of a different string. The two strings become one longer string with two free ends. No loop is completed and strings remain.
Both branches leave strings in the box, each with two free ends, and nothing about the future depends on how long any of those strings is or on which ties produced it. So the whole process restarts on strings, and the expected number of loops still to come is in either case. Conditioning on the first tie, That self-similarity is the whole of the argument. It is also why the answer is a plain sum of reciprocals and not something more intricate: the state of the box is described by a single number, the count of strings, and each tie reduces that count by one at a cost that depends 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 gets there 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 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, so the tie completes a loop with probability . Let be the indicator of that event. The total number of loops is , since every loop is closed by exactly one tie, and expectation adds without any need for independence:

Left: the simulated number of loops from fifty strings over 200,000 trials, with the exact mean dashed in copper; almost every box yields between one and six loops. Right: against on a logarithmic axis, with the asymptote ; the two are indistinguishable beyond the first few values.
The logarithmic crawl
Sums of odd reciprocals reduce to harmonic numbers. Since the even terms are , removing them from leaves the odd ones: Substituting gives with constant . The approximation is already good at fifty: it 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 extra loop costs roughly a sevenfold increase in the yarn. A thousand strings average loops, and a box would need about a hundred thousand strings before the expected count reached seven.
One further remark makes the whole distribution available, not just its mean. The indicators of the previous section 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 for fifty strings: for one loop, for two, for three, for four, and for five, with a standard deviation of . Six loops or fewer covers per cent of boxes. 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.
Python code
The recursion is short enough to be suspicious of, so the check ignores it and plays the game. Shuffle the ends into a random pairing, walk through the pairs, and use a disjoint-set structure over the strings: if the two ends already belong to the same string a loop has closed, otherwise the two strings merge. 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 .
Peter Winkler, Monthly Mindbenders, National Museum of Mathematics, May 2026, momath.org/mindbenders, a variation of a classic.↩︎