int a=10000,b,c=2800,d,e,f[2801],g;main(){for(;b-c;)f[b++]=a/5; for(;d=0,g=c*2;c-=14,printf("%.4d",e+d/a),e=d%a)for(b=c;d+=f[b]*a, f[b]=d%--g,d/=g--,--b;d*=b);} pi to 800 digits. In 160 characters of code. Woo! 0_o
Erm. Long story short? He fills an integer array up with pertinent values and then recomputes them at every pass, based on the "converging fractions" approach (since Pi is an irrational number, there's no 'final digit' or 'final answer' - everything's an approximation, at best).
It's long-winded and complex and made my head explode and I'm not doing it again. =P (I ditched the notepad file I was using to store values *twitch*)
I haven't actually tried it... but I'm fairly sure (from looking at his code) that you could probably change the 2800 and 2801 in the declarations at the start of the code to something larger (say, 9500 and 9501) and get a much closer approximation (with lots more digits).
You could probably get the loops that store and recompute f[] index values to output TDs in HTML so you could see the changes... but only if you wanted to fall asleep. ;)
and the last digit is the correct one but where you to finish your number there you'd round up.
Still fairly impressive,
beats the question though ... How did anyone find that out???
Oh well.
Lambert
(P.S.: And yes I did get the C compiler out and checked it ... sad I know)
Reply
But still. Woo.
Reply
That's the question.
Reply
Reply
Reply
I've been sitting here working out the maths behind what he did.
Makes sense, now. =)
Reply
I have neither the time nor the will to work out how it works.
Reply
It's long-winded and complex and made my head explode and I'm not doing it again. =P (I ditched the notepad file I was using to store values *twitch*)
I haven't actually tried it... but I'm fairly sure (from looking at his code) that you could probably change the 2800 and 2801 in the declarations at the start of the code to something larger (say, 9500 and 9501) and get a much closer approximation (with lots more digits).
You could probably get the loops that store and recompute f[] index values to output TDs in HTML so you could see the changes... but only if you wanted to fall asleep. ;)
Reply
Leave a comment