Skip to content

Instantly share code, notes, and snippets.

@rmamba
Last active April 21, 2017 09:36
Show Gist options
  • Save rmamba/69be59413f1ea95b13f39df0aa14d672 to your computer and use it in GitHub Desktop.
Save rmamba/69be59413f1ea95b13f39df0aa14d672 to your computer and use it in GitHub Desktop.
Pi numbers
def make_pi(R):
q, r, t, k, m, x = 1, 0, 1, 1, 3, 3
for j in range(R):
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(1000)
pi_list = []
my_array = []
for i in make_pi():
my_array.append(str(i))
my_array = my_array[:1] + ['.'] + my_array[1:]
big_string = "".join(my_array)
print "here is a big string:\n %s" % big_string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment