Skip to content
Vamshi Jandhyala

Books · The Riddler

Chapter 3

Can You Find Your Pills?

I’ve been prescribed to take 1.51.5 pills of a certain medication every day for 1010 days, so I have a bottle with 1515 pills. Each morning, I take two pills out of the bottle at random.

On the first morning, these are guaranteed to be two full pills. I consume one of them, split the other in half using a precision blade, consume half of that second pill, and place the remaining half back into the bottle.

On subsequent mornings when I take out two pills, there are three possibilities:

I get two full pills. As on the first morning, I split one and place the unused half back into the bottle. I get one full pill and one half-pill, both of which I consume. I get two half-pills. In this case, I take out another pill at random. If it’s a half-pill, then I consume all three halves. But if it’s a full pill, I split it and place the unused half back in the bottle. Assume that each pill, whether it is a full pill or a half-pill, is equally likely to be taken out of the bottle.

On the 1010th day, I again take out two pills and consume them. In a rush, I immediately throw the bottle in the trash before bothering to check whether I had just consumed full pills or half-pills. What’s the probability that I took the full dosage, meaning I don’t have to dig through the trash for a remaining half-pill?

Solution

Track the bottle by its contents (f,h)(f,h), the number of full pills and half-pills. The whole process is a Markov chain on these states. Drawing two of the t=f+ht=f+h pills, the three immediate outcomes and their probabilities are two full (f2,h+1): (f2)/(t2),one of each (f1,h1): fh/(t2),two halves: (h2)/(t2).\begin{aligned} \text{two full}\ (f{-}2,h{+}1) &:\ \binom{f}{2}\big/\binom{t}{2},\\ \text{one of each}\ (f{-}1,h{-}1) &:\ fh\big/\binom{t}{2},\\ \text{two halves} &:\ \binom{h}{2}\big/\binom{t}{2}. \end{aligned} In the two-halves case a third pill is drawn from the remaining t2t-2: it is full with probability f/(t2)f/(t-2), sending (f,h)(f1,h1)(f,h)\to(f-1,h-1) (split it, return a half), or a half with probability (h2)/(t2)(h-2)/(t-2), sending (f,h)(f,h3)(f,h)\to(f,h-3).

I have taken the full dosage exactly when the bottle empties on the tenth draw, that is, when exactly two pills remain after the first nine mornings. Pushing the distribution from (15,0)(15,0) forward nine days and summing the weight on states with f+h=2f+h=2 gives the exact P=805291019200.7901.P = \frac{80529}{101920} \approx \boxed{0.7901}.

The computation

Evolve the exact distribution over (f,h)(f,h) states with rational arithmetic: each day, redistribute every state’s probability across the four outcomes above, then read off the total probability on the two-pill states after nine days.

from fractions import Fraction as F
from math import comb
from collections import defaultdict
dist = {(15, 0): F(1)}
for _ in range(9):
    nd = defaultdict(F)
    for (f, h), pr in dist.items():
        t = f + h
        if t < 2: nd[(f, h)] += pr; continue              # fewer than two pills: carry
        c2 = F(1, comb(t, 2))
        if f >= 2: nd[(f-2, h+1)] += pr*comb(f, 2)*c2          # two full
        if f and h: nd[(f-1, h-1)] += pr*(f*h)*c2              # one full, one half
        if h >= 2:                                            # two halves, draw a third
            p2h = comb(h, 2)*c2
            if t > 2:
                nd[(f-1, h-1)] += pr*p2h*F(f, t-2)            # third is full: split it
                nd[(f, h-3)]   += pr*p2h*F(h-2, t-2)          # third is half: consume all
            else:
                nd[(f, h-3)]   += pr*p2h                      # no third pill to draw
    dist = nd
print(sum(pr for (f, h), pr in dist.items() if f + h == 2))   # 80529/101920