From Hugh Noland ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ CB> You know, instead of just posting code for these things, it sure > would be nice to see the algorithm behind them! O.K., here's the e-spigot algorithm: 1. Initialize: Let the first digit be 2 and initialize an array A of length n+1 to (1,1,...,1). 2. Repeat n-1 times: Multiply by 10: Multiply each entry of A by 10. Take the fractional part: Starting from the right, reduce the i-th entry of A modulo i+1, carrying the quotient one place left and adding it to the (i-1)-th entry of A. Output the next digit: The final quotient is the next digit of e. Here is an example for n = 3: 2 3 4 5 -- modulus 2 1 1 1 1 -- A 10 10 10 10 -- 10*A 7 4 3 2 -- -- (10*A+q)/(i+1) = q \ | \ | \ | \ | 14 13 12 10 -- 10*A+q | | | | 0 1 0 0 -- (10*A+q) mod (i+1) = A 0 10 0 0 -- 10*A 1 3 0 0 -- -- q \ | \ | \ | \ | 3 10 0 0 -- 10*A+q The first n (= 3) digits of e occur in the first column. The algorithm for pi is a good bit more complicated. If you really want to see it, you'll need to go to the article mentioned. Maybe your public library could have the U of Arkansas library mail a copy; or maybe you could get access to the article via the Internet.