Skip to content

Instantly share code, notes, and snippets.

@igor47
Last active July 8, 2019 23:07
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 igor47/7358a6e6ef0e750b84c8a116d7ab36e5 to your computer and use it in GitHub Desktop.
Save igor47/7358a6e6ef0e750b84c8a116d7ab36e5 to your computer and use it in GitHub Desktop.
from collections import defaultdict
import random
def left_or_right():
return 'l' if random.randint(0, 9) == 0 else 'r'
def make_group():
d = defaultdict(lambda: 0)
for i in range(45):
d[left_or_right()] += 1
return d
def count_groups():
more_than_14 = 0
trials = 100000
for i in range(1000):
d = make_group()
if d['l'] / sum(d.values()) > 0.14:
more_than_14 += 1
print(f"got more than 14% left-handed {(more_than_14 / trials) * 100}% of the time")
if __name__ == "__main__":
count_groups()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment