Last active
July 8, 2019 23:07
-
-
Save igor47/7358a6e6ef0e750b84c8a116d7ab36e5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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