Skip to content

Instantly share code, notes, and snippets.

@mallman
Created February 23, 2012 03:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mallman/1889911 to your computer and use it in GitHub Desktop.
Save mallman/1889911 to your computer and use it in GitHub Desktop.
LA Coding Dojo, Feb. 22, 2012, Sudheer and Saravana's solution
from random import random
points = [(random(), random(),) for i in range(2000000)]
inside = lambda p: (p[0]**2 + p[1]**2) < 1
i, o = 0, 0
for p in points:
if inside(p): i += 1
else: o += 1
print "Pi:", (float(i)/len(points)) * 4
@mallman
Copy link
Author

mallman commented Feb 23, 2012

Very nice and concise. I think you can omit the variable o.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment