Error in fib.rb for 1.9

1.9 compiles and runs great on PCLinuxOS on my Toshiba Satelite
laptop: P4 1Gb

On cursory benchmarks, 1.9 is 2 ~ 8 times faster than 1.8.6 p111 on
some simple tests.

In the process I noticed the 1.9 fib.rb file in the /benchmarks/other-
lang directory is incorrect,
though fib.rb is correct under the /samples directory in 1.8.6 p111

fib.rb – 1.9.0 incorrect fib(0)=1, should be fib(0)=0
def fib n
if n < 3
1
else
fib(n-1) + fib(n-2)
end
end

fib.rb – 1.8.6 p111 correct for fib(0…n)
def fib n
if n < 2
n
else
fib(n-1) + fib(n-2)
end
end

I see this error time and time again, though I continue to try to
stamp it out.
If the routine claims to produce the fibonacci numbers, produce ALL
the correct ones.
See about fibonacci series/numbers here;


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs