Skip to content

Instantly share code, notes, and snippets.

@macterra
Forked from anonymous/landsburgsmoneyredux.py
Created December 29, 2010 18:51
Show Gist options
  • Save macterra/758882 to your computer and use it in GitHub Desktop.
Save macterra/758882 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import random, sys
nCouples = int(sys.argv[1])
iters = int(sys.argv[2])
tot = 0.0
for x in range(iters):
nMales = nCouples
nFemales = nCouples
nSonlessCouples = nCouples
while nSonlessCouples > 0:
for i in range(nSonlessCouples):
if random.randint(0,1)==1:
# it's a boy! stop trying
nMales = nMales + 1
nSonlessCouples = nSonlessCouples - 1
else:
# it's a girl! try again
nFemales = nFemales + 1
tot += 1. * nFemales / (nMales + nFemales)
print tot/float(iters)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment