Chapter 12
Can You Slay The Puzzle Of The Monsters’ Gems?
A video game requires you to slay monsters to collect gems. Every time you slay a monster, it drops one of three types of gems: a common gem, an uncommon gem or a rare gem. The probabilities of these gems being dropped are in the ratio of 3:2:1 (three common gems for every two uncommon gems for every one rare gem, on average). If you slay monsters until you have at least one of each of the three types of gems, how many of the most common gems will you end up with, on average?
The Riddler, FiveThirtyEight(original post)
Solution
The drop ratio makes a gem common with probability , uncommon with , rare with . Let be the expected number of common gems still to come, counting from the moment your collected set of types is , until grows to all three. Every common drop adds one to the tally whether or not you already own a common, so a single slay gives with . We want .
Start with the states that are one type short. When only the rare is missing, each slay ends the hunt with probability and otherwise drops a common with probability ; solving gives . The same step gives (only the uncommon missing) and (only the common missing, and the completing drop is itself a common).
Feeding these back one level produces , , , and finally
The computation
Play it out: slay monsters, drawing a common, uncommon or rare with probabilities , until all three types have appeared, and record how many commons were collected. Averaging over many runs lands on .
import numpy as np
rng = np.random.default_rng(0)
runs = 2_000_000
commons = 0
for _ in range(runs):
seen_u = seen_r = False; c = 0
while not (c and seen_u and seen_r): # until all three appear
x = rng.random()
if x < 1/2: # common gem
c += 1
elif x < 5/6: # uncommon gem (1/2 + 1/3)
seen_u = True
else: # rare gem
seen_r = True
commons += c
print(commons / runs) # ~3.65 = 73/20