def pi(digits=100): pi_digits="" SCALE = 10000 ARRINIT = 2000 carry = 0 arr = [ARRINIT]*(digits+1) for i in range(digits, 0, -14): sum = 0 for j in range(i-1,0,-1): sum = sum * j + SCALE * arr[j] arr[j] = sum % (j * 2 - 1) sum = sum / (j * 2 - 1) pi_digits += "%04d" % (carry + sum / SCALE) carry = sum % SCALE return pi_digits
Inga kommentarer:
Skicka en kommentar