Last active
October 11, 2015 10:52
-
-
Save fmasanori/622f9d1afd9aeb462afd to your computer and use it in GitHub Desktop.
pi_generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Pi Generator ref https://mail.python.org/pipermail/edu-sig/2015-September/011317.html | |
def pi_digits(): | |
k, a, b, a1, b1 = 2, 4, 1, 12, 4 | |
while True: | |
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) | |
a, a1 = 10*(a%b), 10*(a1%b1) | |
d, d1 = a//b, a1//b1 | |
pi = pi_digits() | |
print (''.join([str(next(pi)) for i in range(100)])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment