From: "Brian Schröder" Date: 2004-10-06T05:19:00+09:00 Subject: Re: A ruby course Edgardo Hames wrote: > On Wed, 6 Oct 2004 04:36:23 +0900, Brian Schr�der > wrote: > >>Edgardo Hames wrote: >> >>>>>You could extend Integer with a fibonacci method, so that you can >>>>>write something like: >>>>> >>>>>puts 0.fibonacci > 0 >>>>>puts 1.fibonacci > 1 >>>>>puts 5.fibonacci > 5 >>>> >>>>Should be 12, shouldn't it? >>> >>> >>>0.fib > 0 >>>1.fib > 1 >>>2.fib > 1 >>>3.fib > 2 >>>4.fib > 3 >>>5.fib > 5 >>> >> >>Oh, 12 was the sum of the fibonaccy numbers up to 5. Too much thinking >>is bad for your brain. >> > > > What are you talking about? As far as I know the fibonacci series is defined as > > fib n = fib (n-1) + fib (n-2) > > Then, > fib 5 = > = fib 4 + fib 3 > = (fib 3 + fib 2) + (fib 2 + fib 1) > = ((fib 2 + fib 1) + (fib 1 + fib 0)) + (fib 1 + fib 0) + (1+0) > = ((fib 1 + fib 0) + (1+ 0))+ (1+0) + (1+0) + (1+ 0) > = 1+1+1+1+1 > = 5 > > You might cosider taking a look at > http://mathworld.wolfram.com/FibonacciNumber.html > It defines fib 0 = 0, but either way, 12 doesn't belong to the series. > > Regards, > Ed > I meant "bad for _my_ brain". Sorry if I have confused you. You were absolutely right, and I calculated the wrong thing. Regards, Brian -- Brian Schr�der http://ruby.brian-schroeder.de/