Skip to content

Instantly share code, notes, and snippets.

@GavalasDev
Created August 24, 2022 11:42
Show Gist options
  • Save GavalasDev/582f1b9676ccd337caca4d6d71f06fc0 to your computer and use it in GitHub Desktop.
Save GavalasDev/582f1b9676ccd337caca4d6d71f06fc0 to your computer and use it in GitHub Desktop.
A fast spigot algorithm for the digits of Tau.
"""
This algorithm is based on an unproven conjecture but successfully produces at least the first 600 thousand digits.
Read more about it here: https://www.gavalas.dev/blog/spigot-algorithms-for-pi-in-python/
"""
def gospers_tau_unproven():
q,r,t,i = 1, 180, 30, 2
while True:
u,y = 3*(3*i+1)*(3*i+2), (q*(27*i-12)+5*r)//(5*t)
yield y
q,r,t,i = 10*q*i*(2*i-1),10*u*(q*(5*i-2)+r-y*t),t*u,i+1
tau = gospers_tau_unproven()
print([next(tau) for _ in range(10)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment