Logo

Programming-Idioms

History of Idiom 31 > diff from v1 to v2

Edit summary for version 2 by :

Version 1

2015-05-06, 21:04:49

Version 2

2015-07-31, 19:46:17

Idiom #31 Recursive factorial (simple)

Create recursive function f which returns the factorial of non-negative integer i, calculated from f(i-1)

Idiom #31 Recursive factorial (simple)

Create recursive function f which returns the factorial of non-negative integer i, calculated from f(i-1)

Code
sub f {
   my $n = shift;
   return $n<0 ? 1 : $n * f($n-1);
}