Chapter 270
Can You Stay In Your Lane?
Riddler Express
A pool has five lanes, and swimmers may not use adjacent lanes. Swimmers arrive one at a time and each picks uniformly at random among the lanes still available (empty and not adjacent to an occupied lane), until none remain. What is the expected number of swimmers? Extra credit: with lanes?
The Riddler, FiveThirtyEight, July 3, 2020(original post)
Solution
When the first swimmer takes lane , lane and its neighbours are removed, splitting the remaining lanes into two independent blocks: lanes on the left and on the right. Each block then fills by the same rule, independently, so the expected counts add. Writing for the expected number of swimmers among lanes in a row, with , (and negative indices zero). This is exactly the “random sequential adsorption” recurrence. Evaluating it for five lanes, For the extra credit, the fraction of lanes filled, , settles between the best case (, alternating lanes) and the worst (, two gaps each), approaching the classic Rényi parking constant
The computation
Encode the recurrence (which captures the actual lane-by-lane filling, since the two sides fill independently) and read off ; then watch approach the limiting density.
from fractions import Fraction as F
import math
def table(N, zero, one): # iterative fill of E[0..N]
E = [zero] * (N + 1)
if N >= 1: E[1] = one
for n in range(2, N + 1):
E[n] = 1 + sum(E[max(k - 2, 0)] + E[max(n - k - 1, 0)]
for k in range(1, n + 1)) / n
return E
print("E(5) =", table(5, F(0), F(1))[5]) # 37/15 (exact)
E = table(500, 0.0, 1.0) # float for the density
print("density E(500)/500 =", round(E[500] / 500, 4),
" limit =", round((1 - math.e**-2) / 2, 4))
# E(5) = 37/15
# density E(500)/500 = 0.4329 limit = 0.4323
Riddler Classic
The stars on the flag form a pattern that works because is twice a square. A proposed -star design uses a centre star ringed by concentric pentagons, which works because is a centered pentagonal number. So has the property that is twice a square and is a centered pentagonal number. What is the next integer with both properties?
The Riddler, FiveThirtyEight, July 3, 2020(original post)
Solution
“Twice a square” means . A centered pentagonal number is (a central dot plus rings of ), so requiring to be one gives , that is The pair gives . This is a Pell-type relation, and its solutions grow fast; the next one is , giving with the st centered pentagonal number. (After that the next is .)
The computation
Encode both properties directly: sweep , form , and test whether is centered pentagonal (a value ). Report the values past .
cps = {(5 * m * m - 5 * m + 2) // 2 for m in range(1, 100000)} # centered pentagonals
out = []
x = 1
while len(out) < 3:
N = 2 * x * x
if N + 1 in cps: out.append(N)
x += 1
print(out) # [50, 16200, 5216450]