## Problem

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?

## Solution

```
from random import random
= 100000
runs = 0
total_c for _ in range(runs):
= 0, 0, 0
c, u, r while(True):
= random()
p if p <= 1/6:
+= 1
r elif p >= 1/6 and p <= 1/2:
+= 1
u else:
+= 1
c if c > 0 and r > 0 and u > 0:
break
+= c
total_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\).