Skip to content

Instantly share code, notes, and snippets.

@maxhodak
Last active June 8, 2016 18:35
Show Gist options
  • Save maxhodak/6c7e803c195dd71a573469904eb6c4ac to your computer and use it in GitHub Desktop.
Save maxhodak/6c7e803c195dd71a573469904eb6c4ac to your computer and use it in GitHub Desktop.
from __future__ import division
import random
# question: consider a society that allows only a single child,
# unless your first child is a girl, in which case you can have
# one more child. does this policy introduce a male gender bias?
N = 1000
boys = 0
for _ in xrange(N):
if random.randint(0, 1) > 0: # is a boy
boys = boys + 1
else: # first child is a girl
N = N + 1
boys = boys + random.randint(0, 1)
print("Boys: %d, Girls: %d" % (boys, N - boys))
# => Boys: 732, Girls: 268
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment