good chemistry is complicated,and a little bit messy -LW PerlMonks

### 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

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.

Create A New User
Node Status?
node history
Node Type: note [id://429942]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2018-03-25 02:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
When I think of a mole I think of:

Results (299 votes). Check out past polls.

Notices?