Chapter 5
How Long Will Your Smartphone Distract You From Family Dinner?
You’ve just finished unwrapping your holiday presents. You and your sister got brand-new smartphones, opening them at the same moment. You immediately both start doing important tasks on the Internet, and each task you do takes one to five minutes. (All tasks take exactly one, two, three, four or five minutes, with an equal probability of each). After each task, you have a brief moment of clarity. During these, you remember that you and your sister are supposed to join the rest of the family for dinner and that you promised each other you’d arrive together. You ask if your sister is ready to eat, but if she is still in the middle of a task, she asks for time to finish it. In that case, you now have time to kill, so you start a new task (again, it will take one, two, three, four or five minutes, exactly, with an equal probability of each). If she asks you if it’s time for dinner while you’re still busy, you ask for time to finish up and she starts a new task and so on. From the moment you first open your gifts, how long on average does it take for both of you to be between tasks at the same time so you can finally eat? (You can assume the “moments of clarity” are so brief as to take no measurable time at all.)
The Riddler, FiveThirtyEight(original post)
Solution
Model each sibling as a stream of tasks whose lengths are independent and uniform on minutes, so a task lasts minutes on average. A sibling is “between tasks” exactly at the running totals of their task lengths; call these the sibling’s break points. Dinner happens at the first minute that is a break point for both. We want the expected value of that minute.
Look at the integer minute marks and track each sibling by a residual: the number of minutes left on their current task. Both residuals fall by one each minute. When a residual reaches zero that sibling is at a break point and immediately starts a fresh task, drawing a new residual uniform on . A shared break point is a minute at which both residuals reach zero together.
Here is the key observation. At time both siblings open their phones and draw a first task, so the pair of residuals is two independent uniform draws. That is exactly the state of the pair immediately after any shared break point, when both have just started fresh tasks. The process therefore regenerates at every shared break: the stretch from one shared break to the next is a fresh, independent copy of the stretch from time to the first shared break. In particular, the wait we want has the same distribution as a typical gap between consecutive shared breaks.
Now count. The task lengths have greatest common divisor , so for large the chance that a given minute is a break point of one sibling settles down to : one break per task, one task per minutes. The two siblings are independent, so the chance a given large minute is a break point for both is . Shared breaks therefore occur at long-run rate , and a regenerative stream with rate has mean gap equal to the reciprocal, . Since the first shared break after time is one such gap,
The computation
Encode the residual process directly. The state records the minutes left on each sibling’s current task, with . One minute passes; whichever residual was hits zero and is redrawn uniformly, and if both were a shared break has occurred. Writing for the expected further wait from state gives a linear system, solved exactly in rationals; averaging over the equally likely starting states returns the answer.
import sympy as sp
S = [(a, b) for a in range(1, 6) for b in range(1, 6)] # minutes left
idx = {s: i for i, s in enumerate(S)}
M = sp.zeros(len(S), len(S)); c = sp.zeros(len(S), 1)
fifth = sp.Rational(1, 5)
for (a, b) in S:
i = idx[(a, b)]; M[i, i] += 1; c[i] = 1 # one minute passes
if a == 1 and b == 1:
continue # both finish: shared break
elif a == 1: # only A finishes, redraw it
for ap in range(1, 6): M[i, idx[(ap, b - 1)]] -= fifth
elif b == 1: # only B finishes, redraw it
for bp in range(1, 6): M[i, idx[(a - 1, bp)]] -= fifth
else: # neither finishes
M[i, idx[(a - 1, b - 1)]] -= 1
g = M.solve(c) # expected wait per state
print(sum(g[idx[s]] for s in S) / 25) # 9