Chapter 82
Can You Find The Luckiest Coin?
Riddler Express
In a duel of random numbers, your generator has been sabotaged to return a uniform value in instead of , while your opponent’s is a clean uniform . The larger number wins. What is your probability of winning?
Solution
Let your (rigged) number be and your opponent’s be . You win when . For a fixed value inside , the opponent’s number is below it with probability exactly , so With and , The sabotage caps you at but also lifts your floor to ; on balance your average number is , just under the even-odds , so you are a slight underdog.
The computation
Draw the two numbers many times and count how often yours is larger.
import numpy as np
rng = np.random.default_rng(0)
N = 5_000_000
x, y = rng.uniform(0.1, 0.8, N), rng.uniform(0, 1, N)
print(np.mean(x > y)) # ~0.45
Riddler Classic
Flip a million fair coins, discard the tails, flip the survivors again, and repeat. If you ever reach exactly one coin, call it the luckiest. What is the probability you ever have exactly one coin (rather than jumping from two-or-more straight to zero)?
Solution
Let be the probability of eventually reaching exactly one coin starting from . After one round, coins leave heads with probability , and then the game continues as if started with coins. Splitting off the term (all heads, no progress) and solving, Iterating this upward, settles very quickly to a limit, so for a million coins The value does not converge to a single clean constant but wobbles by less than a thousandth as doubles (a faint log-periodic ripple), hovering around .
The computation
Build from the recurrence with exact fractions and read off the large- value.
from fractions import Fraction as F
from functools import lru_cache
from math import comb
@lru_cache(None)
def P(n):
if n == 1: return F(1)
return F(1, 2**n - 1) * sum(comb(n, i) * P(i) for i in range(1, n))
print(float(P(100))) # ~0.7213