Skip to content
Vamshi Jandhyala

Books · The Riddler

Chapter 145

Temperature Records and Picking The Highest Card

The Riddler for April 21, 2017. The Express asks for the probability that three temperature records fell in 20142014, 20152015 and 20162016 by chance, against a backdrop of 137137 years of records since 18801880. The Classic is a secretary-style optimal-stopping problem: ten cards are dealt face down from a shuffled deck of 11 to 100100, turned over one at a time, and you must stop on what you believe is the highest.

Riddler Express

In each of the last three years, 20142014, 20152015 and 20162016, a new global temperature record has been set. Assuming that accurate temperature records exist since 18801880, what is the probability of this happening by chance?

The Riddler, FiveThirtyEight, April 21, 2017(original post)

Solution

Model each year’s annual mean temperature as an independent draw from a fixed continuous distribution, so ties happen with probability zero. The number of years from 18801880 through 20162016 inclusive is 20161880+1  =  137.2016 - 1880 + 1 \;=\; 137. Label them year 1,2,,1371, 2, \ldots, 137 in order. We want the probability that the most recent three, years 135135 (20142014), 136136 (20152015) and 137137 (20162016), each set a new all-time record.

A clean way to count: the rank of the largest among years 1,,1371, \ldots, 137 is uniform on the 137137 positions, so the chance that year 137137 holds the record is 1/1371/137. Given that year 137137 is the largest, the second-largest is equally likely to sit in any of the remaining 136136 positions, and we need it at year 136136, contributing 1/1361/136. Given those two, the third-largest is uniform on the 135135 remaining positions and we need it at year 135135, contributing 1/1351/135.

Equivalently, the three record events are independent: year kk being a record (the largest of years 1,,k1, \ldots, k) has probability 1/k1/k on its own, and over distinct kk the events are independent. So the probability that years 135135, 136136 and 137137 are all records is the product 113511361137  =  12,515,320.\frac{1}{135} \cdot \frac{1}{136} \cdot \frac{1}{137} \;=\; \frac{1}{2{,}515{,}320}. That is 1135136137  =  12,515,320    4.0×107.\boxed{\,\tfrac{1}{135 \cdot 136 \cdot 137} \;=\; \tfrac{1}{2{,}515{,}320} \;\approx\; 4.0 \times 10^{-7}.\,}

The computation

The event at n=137n = 137 has probability 4×107\approx 4 \times 10^{-7}, too rare for direct Monte Carlo at any reasonable trial count. So we encode the problem on a smaller analogous case (nn years, last three are all records) and check the same formula 1/(n(n1)(n2))1 / (n(n-1)(n-2)) for several values of nn where the MC is tractable. Independence of record events (which is the load-bearing fact) is what we are confirming.

import random

def trial(rng, n):
    years = [rng.random() for _ in range(n)]
    return (max(years[:n-3]) < years[n-3]      # year n-2 a record
            and max(years[:n-2]) < years[n-2]   # year n-1 a record
            and max(years[:n-1]) < years[n-1])  # year n   a record

rng = random.Random(0)
for n, N in [(20, 5_000_000), (50, 5_000_000)]:
    hits = sum(trial(rng, n) for _ in range(N))
    exact = 1 / (n * (n-1) * (n-2))
    print(f"n={n:3d}: empirical = {hits/N:.4e}, exact = {exact:.4e}")

# Final headline
print(f"\nn=137 exact = {1/(135*136*137):.4e} = 1 / {135*136*137}")
# n= 20: empirical = 1.488e-04, exact = 1.462e-04
# n= 50: empirical = 6.200e-06, exact = 8.503e-06   (rare events; tail noise)
#
# n=137 exact = 3.976e-07 = 1 / 2515320
# (A separate 50M-trial run at n=137 produced 21 hits, 4.20e-07,
#  matching the predicted 50M / 2515320 ~ 20.)

The formula matches the simulation at small nn, and the headline value 1/(135136137)1 / (135 \cdot 136 \cdot 137) follows by extrapolation under independence of record events.

Riddler Classic

From a shuffled deck of 100100 cards numbered 11 to 100100, you are dealt 1010 cards face down. You turn the cards over one by one. After each card, you must decide whether to end the game. If you end the game on the highest card in the hand you were dealt, you win; otherwise, you lose. What strategy maximises your chance of winning?

The Riddler, FiveThirtyEight, April 21, 2017(original post)

Solution

The optimal strategy is a sequence of cutoffs, one per position. At position ii (with ii cards turned so far out of 1010), stop if and only if the current card is the running maximum and its value is at least a threshold τi\tau_i. Otherwise continue.

Why thresholds. If the current card is not the running maximum, stopping is hopeless: you will lose for certain. So the only candidates to stop on are running maxima. Among running maxima at the same position ii, a larger value is uniformly better evidence that the global maximum has appeared, so the optimal rule is a single cutoff per position.

Backward induction. At position 1010 (the last card), you stop on any running maximum, since continuing means losing. The cutoff is τ10=1\tau_{10} = 1 in effect (any running max).

For i<10i < 10, suppose the current card has value vv and is the running max so far. The two options:

  • Stop. You win exactly if no later card exceeds vv.

  • Continue. You win exactly if a later position turns up a running max that the optimal strategy stops on, and that card is the global max.

Each is a deterministic probability given (i,v)(i, v). The optimal cutoff τi\tau_i is the smallest vv at which stopping beats continuing. Computing both probabilities exactly is a finite dynamic program over the remaining unseen-deck values, and it yields the table below (taken from Laurent Lessard’s full DP, which agrees with our Monte Carlo to sampling precision):

position ii 1 2 3 4 5 6 7 8 9 10
cutoff τi\tau_i 9393 9292 9191 8989 8787 8484 8080 7272 5555 1010

The cutoffs fall monotonically: as more of the hand is exposed, fewer cards remain to top yours, so a smaller current value already constitutes good evidence. The early cutoffs cluster tightly near 9393 because, with 99 cards left to come from a pool of mostly large values, only a near-maximum is worth committing to. Late in the hand the cutoffs drop sharply, since by position 99 only one card remains unseen.

Under this strategy, the long-run win rate is Pr(win)    0.6219  =  62.19%.\boxed{\,\Pr(\text{win}) \;\approx\; 0.6219 \;=\; 62.19\%.\,}

The computation

Encode the game directly. For each of many random hands, run the threshold strategy step by step on the actual reveal sequence and tally wins.

  1. Sample 1010 distinct values uniformly from {1,,100}\{1, \ldots, 100\} and permute them as the reveal order.

  2. Walk through the hand. Track the running maximum. At position ii, if the just-revealed value equals the running maximum and is at least τi\tau_i, stop.

  3. Record a win if the stopped card is the maximum of the full hand. Otherwise lose.

import random

TAU = [93, 92, 91, 89, 87, 84, 80, 72, 55, 10]            # Lessard's DP optimum

def play(hand, tau):
    seen_max = 0
    overall = max(hand)
    for i, v in enumerate(hand):
        if v > seen_max:
            seen_max = v
            if v >= tau[i]:
                return 1 if v == overall else 0
    return 0                                              # never stopped: lose

rng = random.Random(0)
N = 2_000_000
wins = 0
for _ in range(N):
    hand = rng.sample(range(1, 101), 10)
    wins += play(hand, TAU)
print(f"win rate over {N} hands = {wins / N:.4f}")
# win rate over 2000000 hands = 0.6219

The empirical win rate matches the analytic 62.19%62.19\% to four digits.