<font face="arial" size="3"><p style="margin:0;padding:0;">Thanks for posting this.</p>
<p style="margin:0;padding:0;"> </p>
<p style="margin:0;padding:0;">I had to try it out. I found it behaves differently depending on the version of Python you use.</p>
<p style="margin:0;padding:0;"> </p>
<p style="margin:0;padding:0;">Python 3.2.2: pi_digits(79) generates 79 digits:</p>
<p style="margin:0;padding:0;"> </p>
<p style="margin:0;padding:0;">3141592653589793238462643383279502884197169399375105820974944592307816406286208</p>
<p style="margin:0;padding:0;"> </p>
<p style="margin:0;padding:0;">Python 2.6.5: pi_digits(79) generates 81 digits:</p>
<p style="margin:0;padding:0;"> </p>
<p style="margin:0;padding:0;">314159265358979323846264338327950288419716939937510582097494459230781640628620899</p>
<p style="margin:0;padding:0;"> </p>
<p style="margin:0;padding:0;">The 80th and 81st digits generated by Python 2.6.5 are correct, but unasked for. Assuming that the difference in behavior was due to the difference in the behavior of the division operator (what else could it be?) I ran it again using "python -Qnew" and this time got 82 digits:</p>
<p style="margin:0;padding:0;"> </p>
<p style="margin:0;padding:0;">3141592653589793238462643383279502884197169399375105820974944592307816406286208998</p>
<p style="margin:0;padding:0;"> </p>
<p style="margin:0;padding:0;">Bizarre. Tricky. On which version of Python was this generator intended to run, I wonder?</p>
<p style="margin:0;padding:0;"> </p>
<p style="margin:0;padding:0;">David H</p>
<p style="margin:0;padding:0;"> </p>
<p style="margin:0;padding:0;">-----Original Message-----<br />From: "Kirby Urner" <kurner@oreillyschool.com><br />Sent: Saturday, December 22, 2012 5:33pm<br />To: edu-sig@python.org<br />Subject: [Edu-sig] generate digits of pi<br /><br /></p>
<div id="SafeStyles1356216727">
<p style="margin:0;padding:0;">I'm taking the liberty of reposting this generator supplied by Pythonista michel paul on Math Future. He's not the author though.<br /><br /></p>
<blockquote style="margin: 0px 0px 0px 40px; border: none; padding: 0px;">
<div class="gmail_extra">
<div class="gmail_quote">
<div>
<div>def pi_digits(n):</div>
</div>
</div>
</div>
<div class="gmail_extra">
<div class="gmail_quote">
<div>
<div>k, a, b, a1, b1 = 2, 4, 1, 12, 4</div>
</div>
</div>
</div>
<div class="gmail_extra">
<div class="gmail_quote">
<div>
<div>while n>0:</div>
</div>
</div>
</div>
<div class="gmail_extra">
<div class="gmail_quote">
<div>
<div>p, q, k = k*k, 2*k+1, k+1</div>
</div>
</div>
</div>
<div class="gmail_extra">
<div class="gmail_quote">
<div>
<div>a, b, a1, b1 = a1, b1, p*a+q*a1, p*b+q*b1</div>
</div>
</div>
</div>
<div class="gmail_extra">
<div class="gmail_quote">
<div>
<div>d, d1 = a/b, a1/b1</div>
</div>
</div>
</div>
<div class="gmail_extra">
<div class="gmail_quote">
<div>
<div>while d == d1:</div>
</div>
</div>
</div>
<div class="gmail_extra">
<div class="gmail_quote">
<div>
<div>yield int(d)</div>
</div>
</div>
</div>
<div class="gmail_extra">
<div class="gmail_quote">
<div>
<div>n -= 1</div>
</div>
</div>
</div>
<div class="gmail_extra">
<div class="gmail_quote">
<div>
<div>a, a1 = 10*(a%b), 10*(a1%b1)</div>
</div>
</div>
</div>
<div class="gmail_extra">
<div class="gmail_quote">
<div>
<div>d, d1 = a/b, a1/b1</div>
</div>
</div>
</div>
</blockquote>
<br /><br />More context:<br /><br /><a href="https://groups.google.com/d/msg/mathfuture/LA0pMPC6-HE/MBGWxn4ENsUJ">https://groups.google.com/d/msg/mathfuture/LA0pMPC6-HE/MBGWxn4ENsUJ</a><br /><br />Kirby<br /><br /></div></font>