Error in fib.rb for 1.9

J

jzakiya

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;

http://goldennumber.net/fibonser.htm
http://en.wikipedia.org/wiki/Fibonacci_number
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top