in reply to Re: Re: Recursive to Iterative using Closures (Fun with Fibonacci)
in thread Recursive to Iterative using Closures (Fun with Fibonacci)
A recursive solution for Fibonacci fails the first requirement, the "sets" are not independent (it also fails the third requirement). Calculating the factorial is also a common example for recursion, but that fails the the third requirement, making that the overhead of calling subs is significant, and it's not compensated by simpler code. Recursion can't really beat:
my $p = 1; $p *= $_ for 2 .. $n;
Abigail
|
|---|