Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@hcgatewood
Created November 21, 2018 09:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hcgatewood/e3ec94ad555b5c70c526429822b70dc1 to your computer and use it in GitHub Desktop.
Save hcgatewood/e3ec94ad555b5c70c526429822b70dc1 to your computer and use it in GitHub Desktop.
from random import choice
RUNS = 1_000_000
first_3 = []
def mean(lst):
return sum(lst) / len(lst)
for i in range(RUNS):
n_rolls = 0
while True:
roll = choice([1, 2, 3, 4, 5, 6])
n_rolls += 1
if roll == 3:
first_3.append(n_rolls)
break
if roll in [4, 5, 6]:
break
print("average: {}".format(mean(first_3)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment