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?
from random import random runs = 100000 total_c = 0 for _ in range(runs): c, u, r = 0, 0, 0 while(True): p = random() if p <= 1/6: r += 1 elif p >= 1/6 and p <= 1/2: u += 1 else: c += 1 if c > 0 and r > 0 and u > 0: break total_c += c print("Average number of common gems:", total_c/runs)
The average number of common gems collected before we have one of each gem is $3.65$.