Skip to content

Instantly share code, notes, and snippets.

@auselen
Created March 14, 2017 12:51
Show Gist options
  • Save auselen/985e6e06320066e9081345cb5ad5dea9 to your computer and use it in GitHub Desktop.
Save auselen/985e6e06320066e9081345cb5ad5dea9 to your computer and use it in GitHub Desktop.
Pi approximation
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