Skip to content

Instantly share code, notes, and snippets.

@yue82
Last active June 6, 2016 05:38
Show Gist options
  • Save yue82/1703041023906a806994897a0380d715 to your computer and use it in GitHub Desktop.
Save yue82/1703041023906a806994897a0380d715 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import random
np = lambda : random.random()*2-1
pi = lambda N: sum([1.0 for i in xrange(N) if np()**2+np()**2 <= 1.0]) * 4.0 / float(N)
print pi(100000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment