<div dir="ltr"><font face="tahoma,sans-serif">I realized something. This was the original version:</font><div><font face="tahoma,sans-serif"><br></font></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">
<div style><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.727272033691406px"><div class="gmail_quote" style>def pi_digits():</div></div></div><div style><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.727272033691406px">
<div class="gmail_quote" style>    k, a, b, a1, b1 = 2, 4, 1, 12, 4</div></div></div><div style><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.727272033691406px"><div class="gmail_quote" style>    while True:</div>
</div></div><div style><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.727272033691406px"><div class="gmail_quote" style>        p, q, k = k*k, 2*k+1, k+1</div></div></div><div style><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.727272033691406px">
<div class="gmail_quote" style>        a, b, a1, b1 = a1, b1, p*a+q*a1, p*b+q*b1</div></div></div><div style><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.727272033691406px"><div class="gmail_quote" style>
        d, d1 = a/b, a1/b1</div></div></div><div style><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.727272033691406px"><div class="gmail_quote" style>        while d == d1:</div></div></div><div style>
<div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.727272033691406px"><div class="gmail_quote" style>            yield int(d)</div></div></div><div style><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.727272033691406px">
<div class="gmail_quote" style>            a, a1 = 10*(a%b), 10*(a1%b1)</div></div></div><div style><div class="gmail_extra" style="font-family:arial,sans-serif;font-size:12.727272033691406px"><div class="gmail_quote" style>
            d, d1 = a/b, a1/b1</div></div></div></blockquote><div><div class="gmail_extra"><br></div><div class="gmail_extra">I forget where it came from. Like I had mentioned, I had a really bright student awhile back who was really intrigued by this, and he at one point edited it to produce the digits in binary. In the original form the generator never terminates. Somewhere along the line an edit was made to try to get it to terminate at n digits. Probably to make calling it easy to call as in list(pi_digits(n)). </div>
<div class="gmail_extra"><br></div><div class="gmail_extra">- Michel</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Dec 22, 2012 at 5:34 PM, Kirby Urner <span dir="ltr"><<a href="mailto:kurner@oreillyschool.com" target="_blank">kurner@oreillyschool.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Got it, no wrong digits just not always exactly the number you asked for.<br>
<br>This happens often in 3.2 as well:<br><br>>>> exp = ((n,len(list(pi_digits(n)))) for n in range(10000))  # (number asked, number got)<br>
>>> exp2 = ((a,b) for a,b in exp if a != b)  # filter on "not same"<br>>>> for i in range(10): print(next(exp2), end=", ") <br>(2, 3), (4, 5), (10, 11), (16, 17), (18, 19), (22, 23), (28, 31), (29, 31), (30, 31), (34, 36),<br>

<br>Kirby<div class=""><div class="h5"><br><br><br><div class="gmail_quote">On Sat, Dec 22, 2012 at 4:40 PM,  <span dir="ltr"><<a href="mailto:david@handysoftware.com" target="_blank">david@handysoftware.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<font face="arial" size="3"><p style="margin:0px;padding:0px">In each case I asked for only 79 digits, but got 79, 82, and 83 digits depending on whether I was using python 3.2, python 2.6, or python 2.6 with -Qnew, respectively. The digits all seem to be correct, but the algorithm for stopping at digit n seems to be very sensitive.</p>


<p style="margin:0px;padding:0px"> </p>
<p style="margin:0px;padding:0px">David H</p>
<p style="margin:0px;padding:0px"> <br></p></font></blockquote></div>
</div></div><br>_______________________________________________<br>
Edu-sig mailing list<br>
<a href="mailto:Edu-sig@python.org">Edu-sig@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/edu-sig" target="_blank">http://mail.python.org/mailman/listinfo/edu-sig</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div>==================================<br>"What I cannot create, I do not understand."</div><div><br></div><div>- Richard Feynman</div>==================================<br>
"Computer science is the new mathematics."<div><br></div><div>- Dr. Christos Papadimitriou<br>==================================<br></div>
</div></div></div>