Chapter 64
Can You Catch The Cricket?
Riddler Express
A cricket makes two -foot hops, each in an independent uniformly random direction. Of all possible distances from its start, which is the most probable (the peak of the distribution), not the average?
Solution
Let be the angle between the two hops. By the law of cosines the distance from start to finish is , ranging from (hops cancel) to (hops align). With uniform on , the cumulative distribution is and differentiating gives the density This grows without bound as : the density piles up at the far end, because near a wide range of angles all give nearly the same near-maximal distance. So the peak sits at the largest distance,
The computation
Simulate two random unit hops, histogram the end-to-start distances, and report the busiest bin.
import numpy as np
rng = np.random.default_rng(0)
N = 5_000_000
a, b = rng.uniform(0, 2*np.pi, N), rng.uniform(0, 2*np.pi, N)
d = np.hypot(np.cos(a) - np.cos(b), np.sin(a) - np.sin(b))
h, edges = np.histogram(d, bins=200, range=(0, 2))
print((edges[h.argmax()] + edges[h.argmax() + 1]) / 2) # ~1.99 -> 2
Riddler Classic
Two identical dice, each numbered to , are weighted so that the eleven possible sums through are as close to equally likely as possible. Choosing the weighting that minimises the variance of those eleven probabilities, what should the probabilities of the six faces be?
Solution
Let be one die’s face probabilities, summing to . Since the dice are identical and independent, each sum’s probability is a convolution, for example and we minimise . The objective is symmetric under relabelling a face as , so the optimum is symmetric, , and the minimiser pushes weight toward the extreme faces to lift the otherwise-rare sums and : giving a minimum variance of about , far flatter than fair dice. (If the two dice were allowed to differ, one could do better still, but the puzzle fixes them identical.)
The computation
Minimise the variance of the eleven sum-probabilities over the six face weights, constrained to sum to .
import numpy as np
from scipy.optimize import minimize
def variance(p):
s = {}
for i in range(6):
for j in range(6):
s[i + j] = s.get(i + j, 0) + p[i] * p[j]
return sum((v - 1 / 11)**2 for v in s.values()) / 11
con = [{'type': 'eq', 'fun': lambda p: sum(p) - 1}]
best = min((minimize(variance, np.random.dirichlet(np.ones(6)),
bounds=[(0, 1)]*6, constraints=con) for _ in range(40)),
key=lambda r: r.fun)
print(round(best.fun, 6), np.round(best.x, 3)) # 0.001217, [.244 .137 ..]