<div dir="ltr"><div><div><div><br></div>Wow, I never even guessed Guido had anything to do with this code. The world shrinks again!<br><br></div>Fun!<br><br></div>Kirby<br><br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Sep 29, 2015 at 9:41 AM, Tim Peters <span dir="ltr"><<a href="mailto:tim.peters@gmail.com" target="_blank">tim.peters@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Copying Guido because he's the actual original author of this code. I<br>
remember it being in a very early intro to Python, which I can't find<br>
now. And it used to be included in a Python distribution's Demo<br>
directory. But, e.g., you can see it in this mailing list message<br>
from Guido in 1994, during an early discussion of what eventually<br>
became Python's generators. Guido, do you remember where this<br>
algorithm came from?<br>
<br>
<a href="http://legacy.python.org/search/hypermail/python-1994q2/0429.html" rel="noreferrer" target="_blank">http://legacy.python.org/search/hypermail/python-1994q2/0429.html</a><br>
scroll down to point "6)"<br>
<br>
[kirby urner <<a href="mailto:kirby.urner@gmail.com">kirby.urner@gmail.com</a>>]<br>
<div class="HOEnZb"><div class="h5">> I'm still interested in finding more bibliographic sources for this one, not<br>
> necessarily in Python syntax i.e. did Euler come up with this or who?<br>
><br>
><br>
> def pi_digits():<br>
><br>
> k, a, b, a1, b1 = 2, 4, 1, 12, 4<br>
> while True:<br>
> p, q, k = k*k, 2*k+1, k+1<br>
> a, b, a1, b1 = a1, b1, p*a+q*a1, p*b+q*b1<br>
> d, d1 = a/b, a1/b1<br>
> while d == d1:<br>
> yield int(d)<br>
> a, a1 = 10*(a%b), 10*(a1%b1)<br>
> d, d1 = a/b, a1/b1<br>
><br>
> [ <a href="http://mail.python.org/pipermail/edu-sig/2012-December/010728.html" rel="noreferrer" target="_blank">http://mail.python.org/pipermail/edu-sig/2012-December/010728.html</a> ]<br>
><br>
>>>> pi = pi_digits()<br>
>>>> "".join([str(next(pi)) for i in range(100)]))<br>
> '3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067'<br>
><br>
> ... so far what we know is some high school student handed it in for<br>
> homework.<br>
</div></div></blockquote></div><br></div>