Skip to content
Vamshi Jandhyala

Books · The Riddler

Chapter 14

The Puzzle Of Misanthropic Neighbours

The misanthropes are coming. Suppose there is a row of some number, NN, of houses in a new, initially empty development. Misanthropes are moving into the development one at a time and selecting a house at random from those that have nobody in them and nobody living next door. They keep on coming until no acceptable houses remain. At most, one out of two houses will be occupied; at least one out of three houses will be. But what’s the expected fraction of occupied houses as the development gets larger, that is, as NN goes to infinity?

The Riddler, FiveThirtyEight(original post)

Solution

Let EnE_n be the expected number of occupied houses in a clean row of nn, meaning a block with empty houses and no occupied neighbour just outside either end. The first misanthrope picks one of the nn houses uniformly. If they take house kk, that house is occupied and houses k1k-1 and k+1k+1 become forbidden, splitting what remains into two independent clean rows of lengths k2k-2 and nk1n-k-1. Averaging over kk, and using that the two pieces contribute symmetrically, En=1+2nj=0n2Ej,E0=0, E1=1.E_n = 1 + \frac{2}{n}\sum_{j=0}^{n-2} E_j, \qquad E_0 = 0,\ E_1 = 1.

To extract the large-nn behaviour, gather the EnE_n into the generating function G(x)=n0EnxnG(x) = \sum_{n\ge 0} E_n x^n. Multiplying the recurrence by nxnn x^n and summing turns it into the differential equation G(x)=1(1x)2+2x1xG(x),G'(x) = \frac{1}{(1-x)^2} + \frac{2x}{1-x}\,G(x), a first-order linear ODE. Its integrating factor is (1x)2e2x(1-x)^2 e^{2x}, and solving with G(0)=0G(0)=0 gives the closed form G(x)=1e2x2(1x)2.G(x) = \frac{1 - e^{-2x}}{2\,(1-x)^2}. Now read off the density. The factor 1/(1x)2=(n+1)xn1/(1-x)^2 = \sum (n+1)x^n carries coefficients growing like nn, while the analytic factor (1e2x)/2(1-e^{-2x})/2 tends to (1e2)/2(1-e^{-2})/2 as x1x \to 1. So En/nE_n / n converges to that constant, and the limiting occupied fraction is limNENN=1e220.4323.\lim_{N\to\infty} \frac{E_N}{N} = \frac{1 - e^{-2}}{2} \approx \boxed{0.4323}. This sits, as promised, between 13\tfrac13 and 12\tfrac12.

The computation

Run the development directly: repeatedly pick a uniformly random house that is empty with empty neighbours, occupy it, forbid its neighbours, and continue until none remain. For a long row the occupied fraction settles near 0.43230.4323.

import numpy as np
rng = np.random.default_rng(0)
n, runs = 2000, 4000
total = 0
for _ in range(runs):
    free = set(range(n)); occupied = 0
    while free:
        h = rng.choice(list(free))       # a random allowed house
        occupied += 1
        free.discard(h)
        free.discard(h - 1); free.discard(h + 1)   # forbid neighbours
    total += occupied
print(total / (n * runs))                # ~0.4323 = (1 - e**-2) / 2