From: Thorsten Hater Date: 2010-01-11T22:57:39+09:00 Subject: Re: [QUIZ] Digits of e (#226) Hello, based on the spigot algorithm of Rabonitz and Wagon [1]: #!/usr/bin/ruby def spigot n e = [] arr = [2] + Array.new(n+1,1) (n-1).times do |i| (n+1).downto 0 do |j| arr[j] *= 10 end q = 0 (n+1).downto 0 do |j| arr[j] += q q = arr[j]/(j+1) arr[j] %= j+1 end e << q end e[0]/= 10.0 puts e.join('') end if $0 == __FILE__ spigot ARGV[0].to_i end [1] http://www.mathpropress.com/stan/bibliography/spigot.pdf : citing the easier case of e Am 08.01.2010 06:26, schrieb Daniel Moore: > -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- > > The three rules of Ruby Quiz: > > 1. Please do not post any solutions or spoiler discussion for this > quiz until 48 hours have elapsed from the time this message was > sent. > > 2. Support Ruby Quiz by submitting ideas and responses > as often as you can. > > 3. Enjoy! > > Suggestion: A [QUIZ] in the subject of emails about the problem > helps everyone on Ruby Talk follow the discussion. Please reply to > the original quiz message, if you can. > > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > > RSS Feed: http://rubyquiz.strd6.com/quizzes.rss > > Suggestions?: http://rubyquiz.strd6.com/suggestions > > -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- > > ## Digits of e (#226) > > Wayumbe Rubyists, > > The mathematical constant e is the unique real number such that the > value of the derivative (slope of the tangent line) of the function > f(x) = e^x at the point x = 0 is exactly 1. The function e^x so > defined is called the exponential function, and its inverse is the > natural logarithm, or logarithm to base e.[1] > > e is one of the most important numbers in mathematics, alongside the > additive and multiplicative identities 0 and 1, the constant �, and > the imaginary unit i. These are the five constants appearing in one > formulation of [Euler's identity][2]. > > This week�s 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 > > -- Thorsten Hater Institut fuer Theoretische Physik I Ruhr-Universitaet Bochum E-Mail: tp1@tp1.rub.de Tel.: 0234/32-23-441