[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] algorithm to calculate pi



		       On Sun, 25 Jun 2000 16:37:34 PDT,
			      "Perl lover" wrote:
:looking for a short one in Perl. saw one in C:
:
:long a=10000, b,c=2800,d,e,f[2801],g;
:
:int main(int argc, char* argv[]) {
:     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);
:     return 0;
:}
:
:gets pi's first 280 digits..

I can't promise 280 digits, but here's something shorter:

#!/usr/bin/perl -l
for(0..9999){$i=$_*8;$p+=(16**-$_)*(4/($i+1)-2/($i+4)-1/($i+5)-1/($i+6))}print$p

Michael

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe