Created
March 14, 2017 12:51
-
-
Save auselen/985e6e06320066e9081345cb5ad5dea9 to your computer and use it in GitHub Desktop.
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 | |
l = lambda (a, b), c: (a + c, b + 1) | |
g = (1 if random()**2 + random()**2 <= 1 else 0 for i in range(10**6)) | |
r, t = reduce(l, g, (0.0, 0)) | |
print r / t * 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment