Skip to content

Instantly share code, notes, and snippets.

@ncot-tech
Created March 13, 2024 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ncot-tech/4b109dca121f7e02fd21a6314f4dd645 to your computer and use it in GitHub Desktop.
Save ncot-tech/4b109dca121f7e02fd21a6314f4dd645 to your computer and use it in GitHub Desktop.
gauss-legendre pi calculation algorithm
def pi_digits():
q, r, t, k, n, l = 1, 0, 1, 1, 3, 3
decimal = []
for _ in range(100):
if 4 * q + r - t < n * t:
decimal.append(n)
print (n)
time.sleep(1)
q, r, t, k, n, l = (
10 * q, 10 * (r - n * t), t, k, (10 * (3 * q + r)) // t - 10 * n, l
)
else:
q, r, t, k, n, l = (
q * k, (2 * q + r) * l, t * l, k + 1, (q * (7 * k + 2) + r * l) // (t * l), l + 2
)
return decimal
pi_digits()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment