Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re^3: Fibonacci Numbers

by dReKurCe (Scribe)
on Feb 10, 2005 at 22:56 UTC ( #429942=note: print w/replies, xml ) Need Help??

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://429942]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2018-06-19 05:27 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (111 votes). Check out past polls.