[Chicago] Pi generator again
kirby urner
kirby.urner at gmail.com
Thu Apr 18 05:26:27 CEST 2013
I just noticed the formatting of the Pi generator in the Chipy
archives came out like total crap:
http://mail.python.org/pipermail/chicago/2013-April/010969.html
Sorry about that.
Here's a link to where the formatting worked:
http://mail.python.org/pipermail/edu-sig/2012-December/010729.html
I'm gonna blame my slowness to find the Plaintext option in the newest
Gmail interface.
Trying again here with the Python:
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
(if that didn't come through in Plaintext, with indentation, I'm
sorry, I selected it many times)
Kirby
(in Portland (alien lurker))
PS: I have since showed off generator versions of:
Gregory coefficients:
http://mail.python.org/pipermail/edu-sig/2013-April/010829.html
Bernoulli Numbers:
http://mail.python.org/pipermail/edu-sig/2013-April/010831.html
I was inspired by Raymond Hettinger's talk on how cool generators are,
among other Python features (Pycon keynote). I agree.
More information about the Chicago
mailing list