[sci.math] A program to compute E

greg@garnet.berkeley.edu (Greg Kuperberg) (04/05/91)

Since my program to compute Pi has been topped by another program which
is simpler, uses less space, and runs about as fast, I am compelled to
present another program to compute E:

main(){long int d[3301],i=0,j=3300,c=0;printf("2.");
while(j>1)d[j--]=1;while(i++<2000){for(j=3300;j;j--)
{c+=d[j]*1e5;d[j]=c%j;c/=j;}printf("%05d",c);}printf("\n");}

This time I feel safe that the code is hard to beat for brevity,
give or take a few characters.

The algorithm is based on the same idea as the two to compute Pi.
It converts .11111... from base 2,3,4,5,6,... to base 10.  I must
give credit to Kevin Nomura for telling me this algorithm many years
ago.  It inspired my program for computing Pi.  (Alas, my understanding
of Pi was not up to par with my understanding of this trick.)
----
Greg Kuperberg
greg@math.berkeley.edu

gandalf@csli.Stanford.EDU (Juergen Wagner) (04/05/91)

This is comp.compression! Please restrict those PI and E algorithms
(wonder what's coming next) to sci.math.

grrr,
--juergen