Skip to content

Instantly share code, notes, and snippets.

@auselen
Created March 16, 2017 14:11
Show Gist options
  • Save auselen/72715c28ecbe2dc6d6390eaef71d0fdd to your computer and use it in GitHub Desktop.
Save auselen/72715c28ecbe2dc6d6390eaef71d0fdd to your computer and use it in GitHub Desktop.
Shorter Pi approximation
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