Next | The Perl Hardware Store | DC.pm Version | 30 |
sub fib { my ($n) = @_; return $n if $n ==0 || $n == 1; return fib($n-2) + fib($n-1); }
This function is very very slow!
fib(20) computes fib(18) and fib(19)
fib(19) computes fib(18) again, also fib(17)
fib(18) (done twice) also computes fib(17)...
What a waste of time!
Next | Copyright © 2003 M. J. Dominus |