Created
December 23, 2023 04:54
-
-
Save Snbig/da61552b0cc1a5e0e613e0af3e00c43c to your computer and use it in GitHub Desktop.
calculating the digits of π (Chudnovsky algorithm)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
k,a,b,a1,b1=2,4,1,12,4 | |
pi='' | |
digits=30000 | |
while len(pi) < digits: | |
p,q,k=k*k,2*k+1,k+1 | |
a,b,a1,b1=a1,b1,p*a+q*a1,p*b+q*b1 | |
d,d1=a//b,a1//b1 | |
while d == d1 and len(str(d)) < digits: | |
pi+=str(d) | |
a,a1=10*(a%b),10*(a1%b1) | |
d,d1=a//b,a1//b1 | |
print(pi) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment