1234567891011121314151617181920212223242526
sub ackermann{ my ($n, $m, $seen) = @_; $seen = {} unless defined $seen; while(1) { if($n == 0) { $seen->{"$n,$m"} = $m+1; return ($m+1); } elsif($m == 0) { $n--; $m = 1; } else { my $z = $seen->{"$n,".($m-1)}; $m = $z || ackermann($n, $m-1, $seen); $n--; } }}