Daniel Moore wrote:
> This week quiz is to write a Ruby program that can compute the first
> 100,000 digits of e.
> 
> Have fun!
> 
> [1]: http://en.wikipedia.org/wiki/E_(mathematical_constant)
> [2]: http://en.wikipedia.org/wiki/Euler's_identity

I used the fast converging continued fraction series from the first 
Wikipedia article:

# compute e*10**digits as a rounded integer
def calc_e(digits)
   limit = 10**((digits+3)/2)
   p = [2, 3]
   q = [2, 1]
   n = 1
   begin
     if p.length.even?
       a = 4*(4*n-1)
     else
       a = 4*n+1
       n += 1
     end
     p << a*p[-1] + p[-2]
     q << a*q[-1] + q[-2]
   end while p.last <= limit
   (p.last*10**(digits+3)/q.last+500)/1000
end

if __FILE__ == $0
   p calc_e(if ARGV.length.zero? then 100_000 else Integer(ARGV[0]) end)
end

--
Jack Rouse