2016-12-05 22:15:40 +01:00
|
|
|
{ # <-- scoping the cache and bigint clause
|
|
|
|
|
my @cache;
|
|
|
|
|
use bigint;
|
|
|
|
|
sub mfact {
|
|
|
|
|
my ($s, $n) = @_;
|
|
|
|
|
return 1 if $n <= 0;
|
|
|
|
|
$cache[$s][$n] //= $n * mfact($s, $n - $s);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-04-10 21:29:02 -07:00
|
|
|
|
2016-12-05 22:15:40 +01:00
|
|
|
for my $s (1 .. 10) {
|
|
|
|
|
print "step=$s: ";
|
|
|
|
|
print join(" ", map(mfact($s, $_), 1 .. 10)), "\n";
|
2013-04-10 21:29:02 -07:00
|
|
|
}
|