[Shootout-list] Ruby Harmonic
Daniel South
WildCard_25@HotMail.Com
Sun, 20 Mar 2005 17:31:36 +1000
Jabari Zakiya wrote:
| I noticed the harmonic series benchmark listed
| the Ruby version as having an error. I ran the
| code (below) on my Mandrake 10.1 Ofc system
| and it produced the correct result.
|
I'm guessing it's missing the return at the end of the output.
The random benchmark uses
printf "%.9f\n", gen_random(100.0)
and gets correct output
Try changing the printf line so you have
#!/usr/bin/ruby
# http://shootout.alioth.debian.org/
#
# Contributed by Christopher Williams
n = (ARGV[0] || 10000000).to_i
partialSum = 0.0
(1..n).each {|i| partialSum += (1.0 / i) }
printf "%.9f\n", partialSum
--
Daniel South