I'm taking the liberty of reposting this generator supplied by Pythonista
michel paul on Math Future.  He's not the author though.

def pi_digits(n):
    k, a, b, a1, b1 = 2, 4, 1, 12, 4
    while n>0:
         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)
            n -= 1
            a, a1 = 10*(a%b), 10*(a1%b1)
            d, d1 = a/b, a1/b1



More context:

https://groups.google.com/d/msg/mathfuture/LA0pMPC6-HE/MBGWxn4ENsUJ

Kirby
_______________________________________________
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig

Reply via email to