Last active
August 29, 2015 14:22
-
-
Save pprzetacznik/2e54e03579de14798ace to your computer and use it in GitHub Desktop.
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
from random import random | |
NUM_SAMPLES = 10000 | |
def sample(p): | |
x, y = random(), random() | |
return 1 if x*x + y*y < 1 else 0 | |
count = sc.parallelize(xrange(0, NUM_SAMPLES)).map(sample) \ | |
.reduce(lambda a, b: a + b) | |
print "Pi is roughly %f" % (4.0 * count / NUM_SAMPLES) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment