Monday, August 7, 2017

Pi Digit Generator

def make_pi(itr=1000):
    q, r, t, k, m, x = 1, 0, 1, 1, 3, 3
    for j in range(1000):
        if 4 * q + r - t < m * t:
            yield m
            q, r, t, k, m, x = 10*q, 10*(r-m*t), t, k, (10*(3*q+r))//t - 10*m, x
        else:
            q, r, t, k, m, x = q*k, (2*q+r)*x, t*x, k+1, (q*(7*k+2)+r*x)//(t*x), x+2


digits = make_pi(itr=10000)
pi_list = []
my_array = []

for i in make_pi():
    my_array.append(str(i))

my_array = my_array[0:1] + ['.'] + my_array[1:]
big_string = "".join(my_array)

print("Here is the Pi:\n{}".format(big_string ))

Here is the Pi:
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034
82534211706798214808651328230664709384460955058223172535940812848111745028410270193852110
55596446229489549303819644288109756659334461284756482337

No comments:

Post a Comment