Created
November 29, 2011 15:04
-
-
Save redacted/1405104 to your computer and use it in GitHub Desktop.
Tuesday's child problem
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
import random, time, collections, pprint | |
sample = collections.defaultdict(float) | |
now = time.time() | |
known_child = ('M', 2) | |
while sum(sample.values()) < 100000: | |
genders = [random.choice('MF') for dummy in '..'] | |
birthtimes = [random.uniform(0, now) for dummy in '..'] | |
birthdays = [time.localtime(t).tm_wday for t in birthtimes] | |
gendertimes = zip(genders, birthdays) | |
if known_child in gendertimes: | |
gendertimes.remove(known_child) | |
sample[gendertimes[0]] += 1 | |
if (sum(sample.values()) % 10000) == 0: | |
print sum(sample.values()) | |
males,females = [sum(c for (g, t), c in sample.items() if g == gender) | |
for gender in 'MF'] | |
print males / (males + females) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment