Chapter 277
Can You Corral Your Hamster?
The Riddler for August 21, 2020. The Express asks whether a noisy signal count could have come from two independent sources, and the Classic optimises the shape of a hamster pen built from weighted posts and a fixed length of fabric.
Riddler Express
An astrophysics lab records signals in many equal intervals: zero signals in of intervals, one signal in , and two signals in the remaining . Your adviser suggests the pattern comes from two independent sources, each emitting a signal in any interval with some fixed probability. Could the data have come from two such sources?
The Riddler, FiveThirtyEight, August 21, 2020(original post)
Solution
Let the two sources fire independently with probabilities and . Two signals means both fired, so . Zero signals means neither fired, so . Expanding the second equation, , and substituting gives . (The one-signal probability is then automatic, so it carries no new information.)
So and are two numbers with sum and product , hence the roots of Its discriminant is , so there are no real roots. No pair of probabilities reproduces the data:
The computation
Encode the constraints directly: search the unit square for a pair with and , and report the discriminant of the implied quadratic.
import numpy as np
A, B, C = 0.45, 0.38, 0.17 # P(0), P(1), P(2)
# p,q have sum s and product C with s from the zero-signal equation:
# (1-p)(1-q)=A -> 1 - s + C = A -> s = 1 + C - A
s = 1 + C - A # = 0.72
disc = s*s - 4*C # discriminant of x^2 - s x + C
print(round(s, 4), round(disc, 4)) # 0.72 -0.1616 (negative)
# brute-force confirmation: no (p,q) on a fine grid meets both equations
grid = np.linspace(0, 1, 2001)
ok = [(p, q) for p in grid for q in grid
if abs(p*q - C) < 1e-3 and abs((1-p)*(1-q) - A) < 1e-3]
print(len(ok)) # 0
The discriminant is negative and the grid search finds no admissible pair, so the data cannot come from two independent sources.
Riddler Classic
You build a pen for your hamster by wrapping a fabric sheet around vertical posts. The sheet is metre long (so the perimeter is at most metre) and weighs kilogram; each post weighs kilograms. The combined weight of posts and fabric used cannot exceed kilogram. Using posts makes a regular -gon of perimeter . What is the greatest value of for which four posts enclose more area than three?
The Riddler, FiveThirtyEight, August 21, 2020(original post)
Solution
For a fixed perimeter the regular -gon maximises area, so posts give a regular -gon of perimeter . Three posts ( in weight) leave of fabric for an equilateral triangle of area and four posts leave for a square of area Four posts beat three exactly while . The areas are equal when taking positive square roots (both pens have positive side length for small ). Solving the linear equation, Numerically this is Below this value the square wins; above it the triangle does (the heavier four-post frame eats too much of the budget).
The computation
Encode the two areas as functions of and solve symbolically, then confirm the crossover by scanning .
import sympy as sp
k = sp.symbols('k', positive=True)
A3 = sp.sqrt(3) * (1 - 3*k)**2 / 36
A4 = (1 - 4*k)**2 / 16
roots = [r for r in sp.solve(A3 - A4, k) if 0 < r < sp.Rational(1, 4)]
kc = roots[0]
print(sp.nsimplify(kc), float(kc)) # closed form, 0.0896422...
# scan: four posts win below kc, three posts win above it
f = sp.lambdify(k, A4 - A3)
for kk in [0.08, 0.0896, 0.092]:
print(kk, 'four better' if f(kk) > 0 else 'three better')
The solver returns , and the scan confirms four posts win just below it and lose just above it.