Skip to content
Vamshi Jandhyala

Books · The Riddler

Chapter 286

Can You Make An Unfair Coin Fair?

The Riddler for November 6, 2020. The Express compares two treadmill runs where pace, not speed, varies linearly, and the Classic counts the biased-coin probabilities that can simulate a fair coin within three flips.

Riddler Express

Santul runs 2020 miles twice. Run 1 holds a constant 99 minutes per mile. Run 2 starts at 1010 minutes per mile and ends at 88, with his pace (minutes per mile, not speed) changing linearly in time. Which run is faster, and what are the two times?

The Riddler, FiveThirtyEight, November 6, 2020(original post)

Solution

Run 1 is immediate: 20×9=18020 \times 9 = 180 minutes, exactly 33 hours.

For Run 2, let TT be its total time in minutes. Pace varies linearly from 1010 to 88, so at time tt the pace is 102t/T10 - 2t/T minutes per mile and the speed is its reciprocal, 1/(102t/T)1/(10 - 2t/T) miles per minute. The distance must be 2020 miles: 0Tdt102t/T=20.\int_0^T \frac{dt}{10 - 2t/T} = 20. Substituting u=t/Tu = t/T gives T01du102u=T2[ln10ln8]=T2ln54=20T\int_0^1 \frac{du}{10 - 2u} = \frac{T}{2}\big[\ln 10 - \ln 8\big] = \frac{T}{2}\ln\tfrac54 = 20, so T=40ln(5/4)179.26 minutes2 ⁣: ⁣59 ⁣: ⁣15,T = \frac{40}{\ln(5/4)} \approx 179.26 \text{ minutes} \approx \boxed{2\!:\!59\!:\!15}, about 4545 seconds faster than Run 1’s 3 ⁣: ⁣00 ⁣: ⁣003\!:\!00\!:\!00. The pace spends more time near its slow end, but averaging the reciprocal of a linear pace (a logarithm) still edges below the constant 99-minute pace.

The computation

Encode the constraint: integrate the speed 1/(102t/T)1/(10 - 2t/T) over [0,T][0, T], set it to 2020 miles, and solve for TT.

import math
run1 = 20 * 9                          # 180 minutes
T = 40 / math.log(5 / 4)               # solves (T/2) ln(5/4) = 20
mins, secs = int(T), round((T - int(T)) * 60)
print(run1, round(T, 3), f'{mins}:{secs:02d}')   # 180  179.257  179:15

Run 2 takes 40/ln(5/4)179.2640/\ln(5/4) \approx 179.26 minutes, edging out Run 1’s 180180.

Riddler Classic

Von Neumann turns a biased coin (heads probability pp) into a fair one. You want to simulate a fair coin in at most three flips: assign some set of three-flip outcomes to “heads” so their total probability is exactly 12\tfrac12. For how many values of pp is this possible?

The Riddler, FiveThirtyEight, November 6, 2020(original post)

Solution

Three flips give eight outcomes, grouped by their number of heads: p3p^3 (one outcome), p2(1p)p^2(1-p) (three), p(1p)2p(1-p)^2 (three), (1p)3(1-p)^3 (one). A simulation works when some subset of these outcomes has total probability exactly 12\tfrac12. By symmetry every achievable sum is ap3+bp2(1p)+cp(1p)2+d(1p)3=12,a\,p^3 + b\,p^2(1-p) + c\,p(1-p)^2 + d\,(1-p)^3 = \tfrac12, with a,d{0,1}a, d \in \{0,1\} and b,c{0,1,2,3}b, c \in \{0,1,2,3\}, which is 2442=642 \cdot 4 \cdot 4 \cdot 2 = 64 candidate equations. Each is a cubic (or lower) in pp; collecting their roots in (0,1)(0,1) and removing duplicates leaves 19\boxed{19} distinct values of pp. They include the obvious p=12p = \tfrac12, plus p=1/2p = 1/\sqrt2 and 11/21 - 1/\sqrt2 (where p2=12p^2 = \tfrac12 or (1p)2=12(1-p)^2 = \tfrac12, achievable already in two flips), and sixteen others. Extending to at most NN flips gives the counts 1,3,19,271,8635,623533,1, 3, 19, 271, 8635, 623533, \ldots, a sequence only recently catalogued.

The computation

Encode all 6464 subset-sum polynomials, find their roots in (0,1)(0,1), and cluster numerically equal roots before counting.

import numpy as np
p, q = np.poly1d([1, 0]), np.poly1d([-1, 1])      # p and (1 - p)
roots = []
for a in range(2):
    for b in range(4):
        for c in range(4):
            for d in range(2):
                poly = a*p**3 + b*(p**2*q) + c*(p*q**2) + d*q**3 - 0.5
                for r in np.roots(poly.c):
                    if abs(r.imag) < 1e-9 and 1e-9 < r.real < 1 - 1e-9:
                        roots.append(r.real)
roots.sort()
distinct = [r for i, r in enumerate(roots)
            if i == 0 or r - roots[i-1] > 1e-5]      # cluster near-equal roots
print(len(distinct))                              # 19

Nineteen biased-coin probabilities can simulate a fair coin within three flips.