[Shootout-list] Ruby Harmonic

Jabari Zakiya jzakiya@mail.com
Sun, 20 Mar 2005 01:51:26 -0500


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.

What appears to have happened is the listed
benchmark was only run for N=3D6,000,000 and
not the required 10,000,000 terms, and thus
returned the wrong answer (though correct
for 6,000,000 terms in the series).

This benchmark should work as is if you
rerun it with the correct numbet of terms.

Jabari Zakiya
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

#!/usr/bin/ruby
# http://shootout.alioth.debian.org/
#
# Contributed by Christopher Williams
n =3D (ARGV[0] || 10000000).to_i

partialSum =3D 0.0
(1..n).each {|i| partialSum +=3D (1.0 / i) }

printf("%.9f", partialSum)


# for N =3D  6,000,000 sum is 16.184485775
# for N =3D 10,000,000 sum is 16.695311366
--=20
___________________________________________________________
Sign-up for Ads Free at Mail.com
http://promo.mail.com/adsfreejump.htm