Skip to content

Instantly share code, notes, and snippets.

@fmasanori
Created October 28, 2013 23:18
Show Gist options
  • Save fmasanori/7206539 to your computer and use it in GitHub Desktop.
Save fmasanori/7206539 to your computer and use it in GitHub Desktop.
Cálculo de Pi
def pi_digits(n):
k, a, b, a1, b1 = 2, 4, 1, 12, 4
while n > 0:
p, q, k = k*k, 2*k+1, k+1
a, b, a1, b1 = a1, b1, p*a+q*a1, p*b+q*b1
d, d1 = a/b, a1/b1
while d == d1:
yield int(d)
n -= 1
a, a1 = 10*(a%b), 10*(a1%b1)
d, d1 = a/b, a1/b1
print ('Que bruxaria é essa!?')
for d in pi_digits(200):
print (d, end='')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment