Skip to content
Vamshi Jandhyala

Books · The Fiddler: Solutions

Chapter 56

How Many Rides Can You Reserve?

A theme park has 1212 one-hour ride slots (99 a.m. to 99 p.m.). You reserve 33 rides in 33 distinct random slots. After completing each ride you reserve one more, in a uniformly random slot after your latest scheduled ride. You stop once a ride lands in the final (8899 p.m.) slot. On average, how many rides do you get?

The Fiddler, Zach Wissner-Gross, May 2, 2025(original post)

Solution

Each new reservation pushes your latest slot MM forward to a uniform choice in {M+1,,12}\{M+1,\dots,12\}, and you stop when M=12M=12. So the number of extra rides beyond the first three is the number of forward jumps from your starting maximum to 1212. Let f(m)f(m) be that expected number of jumps: f(12)=0,f(m)=1+112mk=m+112f(k).f(12)=0,\qquad f(m)=1+\frac{1}{12-m}\sum_{k=m+1}^{12}f(k). The total is 3+Ef(M0)3+\mathbb{E}\,f(M_0), averaged over M0=maxM_0=\max of three distinct random slots: E[rides]=3+1(123)s{1..12}s=3f(maxs)=118361277204.270.\mathbb{E}[\text{rides}]=3+\frac{1}{\binom{12}{3}}\sum_{\substack{s\subset\{1..12\}\\|s|=3}}f(\max s)=\frac{118361}{27720}\approx\boxed{4.270}.

The computation

Build f(m)f(m) exactly from its recurrence (each value depends only on later slots), then average f(max)f(\max) over every starting triple of slots.

from fractions import Fraction as F
from itertools import combinations
f = {12: F(0)}
for m in range(11, 0, -1):
    f[m] = 1 + sum(f[k] for k in range(m + 1, 13)) * F(1, 12 - m)
num = sum(f[max(s)] for s in combinations(range(1, 13), 3))
print(3 + num / F(220))                   # 118361/27720

Extra Credit

Now each new reservation goes in a random available slot after the ride you just completed (not after your latest), and you continue until no slots remain. On average, how many rides now?

Solution

Reservations can now slot in between existing rides, so the schedule fills up far more. Simulating the process, E[rides]6.81.\mathbb{E}[\text{rides}]\approx\boxed{6.81}. (The source’s value is paywalled; this is my own simulation.)

The computation

Run the booking process itself: keep a set of scheduled slots, advance to the next one after the current ride, and after each ride book a random still-free slot beyond it until none remain.

import random
def run(rng):
    sched = set(rng.sample(range(1, 13), 3)); done = cur = 0
    while True:
        nxt = min((s for s in sched if s > cur), default=None)
        if nxt is None: break
        done += 1; cur = nxt
        avail = [s for s in range(cur + 1, 13) if s not in sched]
        if avail: sched.add(rng.choice(avail))
    return done
rng = random.Random(5)
print(round(sum(run(rng) for _ in range(600_000)) / 600_000, 3))   # ~6.81