diff options
| l--------- | challenge-017/michael-hamlin/perl5/ch-1.pl | 1 | ||||
| -rw-r--r-- | challenge-017/michael-hamlin/perl5/t1-ackermann-simple.pl | 35 |
2 files changed, 36 insertions, 0 deletions
diff --git a/challenge-017/michael-hamlin/perl5/ch-1.pl b/challenge-017/michael-hamlin/perl5/ch-1.pl new file mode 120000 index 0000000000..157cbc0453 --- /dev/null +++ b/challenge-017/michael-hamlin/perl5/ch-1.pl @@ -0,0 +1 @@ +t1-ackermann-simple.pl
\ No newline at end of file diff --git a/challenge-017/michael-hamlin/perl5/t1-ackermann-simple.pl b/challenge-017/michael-hamlin/perl5/t1-ackermann-simple.pl new file mode 100644 index 0000000000..02e03a644f --- /dev/null +++ b/challenge-017/michael-hamlin/perl5/t1-ackermann-simple.pl @@ -0,0 +1,35 @@ +#! /usr/bin/env perl +# + +use 5.22.0; +use warnings; +use feature 'signatures'; +no warnings 'experimental::signatures'; +use integer; + +# really need the big integers when $m >= 4 +# use bigint lib => 'GMP'; + +no warnings 'recursion'; + +my $count = 0; + +sub _ack( $m, $n ) { + $count++; + if ($m > 0) { + return _ack( $m - 1, 1 ) unless $n; + return _ack( $m - 1, _ack( $m, $n - 1)); + } else { + return $n + 1; + } +} +sub ack ( $m, $n ) { + die "the function is not defined for negative parameters" if $m < 0 || $n < 0; + return _ack($m, $n); +} + +die "must give two nonnegative integers as input" unless @ARGV > 1; + +$" = ', '; +say "A( @ARGV ) = ", ack(@ARGV), " ...after $count calls."; + |
