Created
November 21, 2018 09:48
-
-
Save hcgatewood/e3ec94ad555b5c70c526429822b70dc1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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