Skip to content

Instantly share code, notes, and snippets.

@dcchut
Created November 16, 2019 22:32
Show Gist options
  • Save dcchut/7359f2d328b126a5c941c1091dcdf0df to your computer and use it in GitHub Desktop.
Save dcchut/7359f2d328b126a5c941c1091dcdf0df to your computer and use it in GitHub Desktop.
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