# The Riddler – Jems

The most recent riddler was a bit uninspiring but regardless a good exercise. Here is the riddle:

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?
There really wasn’t anything cool that I did besides program the reward structure and run a few million trials. Example results are:

The average run gave out 7.298427 jems.
You’d usually have 3.648356 common jems.
You’d usually have 2.433008 uncommon jems.
You’d usually have 1.217063 rare jems.

```# The Riddler - Jems
#
# Written hastily by Tyler Barron - May 22 2016
import random
import math
import time

totalRuns = 0
trials = 1000000
tcJem = 0
tmJem = 0
trJem = 0
for run in range (1,trials):
collectedRange = 0
cJem = 0
mJem = 0
rJem = 0
while collectedRange ==0:
totalRuns = totalRuns + 1
rng = 1+math.floor(6*random.random())
if rng < 4:
cJem = 1
tcJem = tcJem + 1
elif rng == 6:
rJem = 1
trJem = trJem + 1
else:
mJem = 1
tmJem = tmJem + 1
if (cJem + rJem + mJem) == 3:
collectedRange = 1

averageRun = totalRuns / trials
print("The average run gave out %f jems." % averageRun)
print("You'd usually have %f common jems." % (tcJem/trials))
print("You'd usually have %f uncommon jems." % (tmJem/trials))
print("You'd usually have %f rare jems." % (trJem/trials))
```