Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^3: Fibonacci Numbers

by dReKurCe (Scribe)
on Feb 10, 2005 at 22:56 UTC ( [id://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?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://429942]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-04-24 04:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found