Last active
August 29, 2015 14:10
-
-
Save jxnl/7730df81f682d1ba45ae to your computer and use it in GitHub Desktop.
lol pi.py
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 random | |
| import math | |
| count_total = 10000 | |
| count_inside = 0 | |
| for _ in xrange(count_total): | |
| inside_the_unit_circle = (math.hypot(random.random(), random.random()) < 1) | |
| count_inside += 1 if (inside_the_unit_circle) else 0 | |
| print 4.0 * count_inside / count |
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 random | |
| import math | |
| count = 10000 | |
| total = sum(map(math.hypot(random.random(), random.random()) < 1 for _ in xrange(count)) | |
| print 4.0 * total / count |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment