Created
May 26, 2017 14:41
-
-
Save sdamashek/baeea6c73d0f15a7b6620f28c63d7e97 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
import math | |
import random | |
import sys | |
def main(): | |
num = int(sys.argv[1]) | |
points_in = 0 | |
for _ in range(num): | |
px, py = random.random() * 2 - 1, random.random() * 2 - 1 | |
if (px**2 + py**2) <= 1: | |
points_in += 1 | |
pi_approx = 4.0 * points_in / num | |
print('Approx = {}'.format(pi_approx)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment