Skip to content

Instantly share code, notes, and snippets.

Created December 29, 2010 05:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/758222 to your computer and use it in GitHub Desktop.
Save anonymous/758222 to your computer and use it in GitHub Desktop.
Landsburg's Money Redux
#!/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 = 0.; nFemales = 0.
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