Created
December 29, 2010 05:45
-
-
Save anonymous/758222 to your computer and use it in GitHub Desktop.
Landsburg's Money Redux
This file contains 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
#!/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