Created
April 17, 2018 15:05
-
-
Save FavioVazquez/d500f92732dca3793ce862d7457a6ed8 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
import findspark | |
findspark.init("/opt/spark") | |
import random | |
from pyspark import SparkContext | |
sc = SparkContext(appName="EstimatePi") | |
def inside(p): | |
x, y = random.random(), random.random() | |
return x*x + y*y < 1 | |
NUM_SAMPLES = 1000000 | |
count = sc.parallelize(range(0, NUM_SAMPLES)) \ | |
.filter(inside).count() | |
print("Pi is roughly %f" % (4.0 * count / NUM_SAMPLES)) | |
sc.stop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment