Created
November 16, 2019 22:32
-
-
Save dcchut/7359f2d328b126a5c941c1091dcdf0df 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
import random | |
from collections import Counter | |
def roll(die_size, die_count): | |
return (random.randint(1, die_size) for _ in range(die_count)) | |
def is_good_roll(rolls, threshold): | |
c = Counter(rolls) | |
return any(x >= threshold for x in c.values()) | |
if __name__ == '__main__': | |
trials = 10000000 | |
good_rolls = 0 | |
for _ in range(trials): | |
if is_good_roll(roll(12, 12), 3): | |
good_rolls += 1 | |
print(good_rolls, good_rolls / trials) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment