RosettaCodeData/Task/Multifactorial/Perl/multifactorial-1.pl

15 lines
274 B
Perl
Raw Permalink Normal View History

2023-07-01 11:58:00 -04: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);
}
}
for my $s (1 .. 10) {
print "step=$s: ";
print join(" ", map(mfact($s, $_), 1 .. 10)), "\n";
}