Skip to content

Instantly share code, notes, and snippets.

@thephysicsvirtuosi
Created March 14, 2012 18:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thephysicsvirtuosi/2038329 to your computer and use it in GitHub Desktop.
Save thephysicsvirtuosi/2038329 to your computer and use it in GitHub Desktop.
Ridiculously Fast Pi approximation
from bigfloat import *
N = 5
setcontext(precision(10**N))
def f(x):
return x + sin(x)
def g(n):
x = 3
for i in xrange(n):
x = f(x)
return x
import sympy
goodpi = str(sympy.pi.evalf(10**N))
def goodtill(n):
cand = g(n)
for i,(a,b) in enumerate(zip(str(cand),goodpi)):
if a != b:
return i-1
inds = range(20)
print map(goodtill,inds)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment