Skip to content

Instantly share code, notes, and snippets.

@redacted
Created November 29, 2011 15:04
Show Gist options
  • Save redacted/1405104 to your computer and use it in GitHub Desktop.
Save redacted/1405104 to your computer and use it in GitHub Desktop.
Tuesday's child problem
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