thank you for taking time to read and (hopefully) answer my question! I have recently taken a interest in Pi (π not the edible type, i already love those!) and was intrigued in the calculation of such a number, i can fluently type in moderately advanced python and am a advanced Linux user so i set up a "cluster" of old(ish) computers. after some digging i found a python program that calculates pi, i edited it and made it output to a file,i ran it on one of the computers and it works amazingly, it is currently on about 2 million digits of pi (tiny compared to the world record of 22.7 trillion!) and is using 100% of both cores and 94% of ram, my only issue is that i cannot cancel the process or i ave to start all over, i am trying to understand the algorithm so i can code in a load function. the load function should open the file and continue calculating pi from there onwards. i can understand the algorithm slightly and have figured out it uses the already calculated pi digits to figure out the digits (which explains the speed decay) and so loading in pre calculated data is possible. The code is as followed:
import sys
def calcPi():
q, r, t, k, n, l = 1, 0, 1, 1, 3, 3
while True:
if 4*q+r-t < n*t:
yield n
nr = 10*(r-n*t)
n = ((10*(3*q+r))//t)-10*n
q *= 10
r = nr
else:
nr = (2*q+r)*l
nn = (q*(7*k)+2+(r*l))//(t*l)
q *= k
t *= l
l += 2
k += 1
n = nn
r = nr
pi_digits = calcPi()
i = 0
for d in pi_digits:
sys.stdout =open("piDigits.txt", "a")
sys.stdout.write(str(d))
i += 1
if i == 50:
print("")
i = 0
If anybody could help me find a way to load in the pre-calculated digits of pi and continue calculating from there or explain the algorithm/code to me i would i would be extremely grateful! Thanks in advance. -Leo Cornelius