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
= 100000
runs = 0
total_pref_pct for _ in range(runs):
= set(range(60))
pills = 0
num_pref_pills for _ in range(15):
= sample(pills, 4)
fish4 -= set(fish4)
pills += min(sum([1 if p % 2 == 0 else 0 for p in fish4]), 2)
num_pref_pills += num_pref_pills/30
total_pref_pct print(total_pref_pct/runs)
The percentage of vitamins taken with the preferred flavour is \(82\)%.