in reply to Re^3: fibonacci numbers using subroutine?
in thread fibonacci numbers using subroutine?

I've never said it's the best solution, but only that it follows better the Fibonacci mathematical definition and that it's easier (theoretically) to implement.

But thanks for pointing that things out, I should have done it by myself.

P.S. Yeah, maybe the "no useless loop" wasn't that right as I thought :D

Alessandro Ghedini <http://ghedini.co.cc>
  • Comment on Re^4: fibonacci numbers using subroutine?

Replies are listed 'Best First'.
Re^5: fibonacci numbers using subroutine?
by JavaFan (Canon) on Aug 20, 2010 at 22:10 UTC
    I've never said it's the best solution, but only that it follows better the Fibonacci mathematical definition and that it's easier (theoretically) to implement.
    Actually, most mathematical definitions I've seen are of the form:
        F0 = 0
        F1 = 1
        Fn = Fn-1 + Fn-2, n > 1
    
    which to me doesn't smell like recursion at all. F is defined as a sequence, it's not defined as a function. It's more a way of declaring a list, or an array, if you want to find a programming equivalent. Something like:
    F[0] = 0; F[1] = 1; F[$_] = F[$_-1] + F[$_-2] for 1 .. *;
    (borrowing Perl6's *).

      I give up... your solution beats mine by lots of points.

      I didn't even know you can use loops that way in Perl, so thanks for the mini lesson ;)

      Alessandro Ghedini <http://ghedini.co.cc>