in reply to Re^4: 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.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:
(borrowing Perl6's *).F[0] = 0; F[1] = 1; F[$_] = F[$_-1] + F[$_-2] for 1 .. *;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: fibonacci numbers using subroutine?
by alexbio (Monk) on Aug 22, 2010 at 10:35 UTC |