Probability and vitamin pills

A FiveThirtyEight Riddler puzzle.
mathematics
Riddler
Published

February 2, 2018

Riddler Express

You and your spouse each take two gummy vitamins every day. You share a single bottle of 60 vitamins, which come in two flavors. You each prefer a different flavor, but it seems childish to fish out two of each type (but not to take gummy vitamins). So you just take the first four that fall out and then divide them up according to your preferences. For example, if there are two of each flavor, you and your spouse get the vitamins you prefer, but if three of your preferred flavor come out, you get two of the ones you like and your spouse will get one of each.

The question is, on average, what percentage of the vitamins you take are the flavor you prefer? (Assume that the bottle starts out with a 50-50 split between flavors, and that the four selected each day are selected uniformly at random.)

Solution

from random import sample

runs =  100000
total_pref_pct = 0
for _ in range(runs):
    pills = set(range(60))
    num_pref_pills = 0
    for _ in range(15):
        fish4 = sample(pills, 4)
        pills -= set(fish4)
        num_pref_pills += min(sum([1 if p % 2 == 0 else 0 for p in fish4]), 2)
    total_pref_pct += num_pref_pills/30
print(total_pref_pct/runs)

The percentage of vitamins taken with the preferred flavour is \(82\)%.

Back to top