Tomorrow is pi-day….

Tomorrow is 3/14, known as pi day, or Albert Einstein’s birthday. How better to celebrate than with a script in pi-thon?

#!/usr/bin/env python

from itertools import islice

def g(q, r, t, i):
        while True:
                u, y =3*(3*i+1)*(3*i+2), (q*(27*i-12)+5*r) // (5 * t)
                yield y
                q, r, t, i = 10*q*i*(2*i-1), 10*u*(q*(5*i-2)+r-y*t), t*u, i+1

def pig():
        return g(1,180,60,2)

p = pig()

pistr = ''.join([ str(x) for x in islice(p, 10001)])

print "%s." % pistr[0]

def byn(s, n):
        return [s[x:x+n] for x in range(0, len(s), n)]

for line in byn(pistr[1:], 50):
        for group in byn(line, 5):
                print group,
        print