Throw darts at a unit square, take the fraction that hit a point (x < .7, y < .5) and multiply by 100. (Also works to calculate pi.)
I get 36.0.
#!/usr/bin/python from random import random trials=200 hits=0 for i in range(trials): x=random() y=random() if x<.7: if y<.5: hits+=1 print 100*(float(hits)/float(trials))
It’s samping variation. Set trials = 1e9 and see what you get.
If I knew how to take fractions, I would have just done 7/(1/5).
Throw darts at a unit square, take the fraction that hit a point (x < .7, y < .5) and multiply by 100. (Also works to calculate pi.)
I get 36.0.
It’s samping variation. Set trials = 1e9 and see what you get.
If I knew how to take fractions, I would have just done 7/(1/5).