Created
March 16, 2017 14:11
-
-
Save auselen/72715c28ecbe2dc6d6390eaef71d0fdd to your computer and use it in GitHub Desktop.
Shorter Pi approximation
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 | |
print 4 * reduce(lambda a, (c, d): (a * (d - 1) + c) / d, ((1.0 if random()**2 + random()**2 <= 1 else 0, i) for i in range(1, 10**6)), 0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment