in reply to Re^2: Fibonacci Numbers
in thread Fibonacci Numbers

Honourable friar, Am I wrong to think that recurrsion is utilized by passing the value of $sum as computed by sub fib back into sub fib? Otherwise, the binet formula is extremely cool. Thanks.

Replies are listed 'Best First'.
Re^4: Fibonacci Numbers
by lidden (Curate) on Feb 10, 2005 at 23:33 UTC
    This is a recursive way to do it but it gets slow quickly for larger values unless you memoze it.
    print "$_ : ", fibo($_), "\n" for 0..23; sub fibo{ my $n = shift; if ( $n == 0){ return 0;} elsif( $n == 1){ return 1;} else { return fibo($n-1) + fibo($n-2);} }
Re^4: Fibonacci Numbers
by blazar (Canon) on Feb 11, 2005 at 09:39 UTC
    It is iterative. It is not recursive in that fib() does not call itself.

    FWIW I think that Binet's formula is cool too.