Created
February 23, 2012 04:24
-
-
Save anonymous/1890187 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
#George Vamos | |
# Most simple minded implementation of monte carlo pi | |
import math, random | |
MAX=1000000 | |
hits = 0 | |
rounds = 0 | |
for i in range(MAX): | |
rounds += 1 | |
x=random.random() | |
y=random.random() | |
d = math.sqrt((x*x)+(y*y)) | |
if (d < 1.0): hits += 1 | |
print("%d,%d,%f" % (rounds,hits,((4.0 * hits)/rounds))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment