Xref: utzoo sci.math:16411 comp.compression:237 Newsgroups: sci.math,comp.compression Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!think.com!snorkelwacker.mit.edu!stanford.edu!agate!garnet.berkeley.edu!greg From: greg@garnet.berkeley.edu (Greg Kuperberg) Subject: A program to compute E Message-ID: <1991Apr4.192717.21850@agate.berkeley.edu> Followup-To: sci.math Sender: usenet@agate.berkeley.edu (USENET Administrator) Reply-To: greg@math.berkeley.edu Organization: U.C. Berkeley Date: Thu, 4 Apr 91 19:27:17 GMT Lines: 19 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