[Edu-sig] followup to older post... re Pi generator
kirby urner
kirby.urner at gmail.com
Tue Sep 29 17:46:49 CEST 2015
I'm still interested in finding more bibliographic sources for this one,
not necessarily in Python syntax i.e. did Euler come up with this or who?
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
[ http://mail.python.org/pipermail/edu-sig/2012-December/010728.html ]
>>> pi = pi_digits()
>>> "".join([str(next(pi)) for i in range(100)]))
'3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067'
... so far what we know is some high school student handed it in for
homework.
Kirby
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/edu-sig/attachments/20150929/415e0f2b/attachment.html>
More information about the Edu-sig
mailing list