## Ackermann

### Ackermann Euphoria

```-- The Computer Language Shootout Benchmarks
--   http://shootout.alioth.debian.org/
--
--   contributed by Derek Parnell
--
--   run: exu ackermann.ex [N=1]

without warning
without type_check

include get.e

function Ack(integer M, integer N)
if M = 0 then
return N+1
elsif N = 0 then
return Ack(M-1,1)
end if
return Ack(M-1, Ack(M, N-1))
end function

procedure main(sequence argv)

object n
if length(argv) >= 3 then
n = value(argv[3])
n = n[2]
else
n = 1
end if

printf(1, "Ack(3,%d): %d\n", {n, Ack(3, n)})
end procedure

main(command_line())
```

### Ackermann Python

```#!/usr/local/bin/python
# \$Id: ackermann.python,v 1.7 2001/03/16 15:57:34 doug Exp \$
# http://www.bagley.org/~doug/shootout/
# from Brad Knotwell

import sys

def Ack(M, N):
if (not M):
return( N + 1 )
if (not N):
return( Ack(M-1, 1) )
return( Ack(M-1, Ack(M, N-1)) )

def main():
NUM = int(sys.argv[1])
sys.setrecursionlimit(30000)
print "Ack(3,%d): %d" % (NUM, Ack(3, NUM))

main()

```

### Ackermann Perl

```#!/usr/local/bin/perl
# \$Id: ackermann.perl,v 1.9 2001/05/04 01:21:38 doug Exp \$
# http://www.bagley.org/~doug/shootout/
use strict;
use integer;

# It's prettier but slower to do this
#sub Ack {
#    my(\$M, \$N) = @_;
#    return( \$N + 1 )         if (\$M == 0);
#    return( Ack(\$M - 1, 1) ) if (\$N == 0);
#    Ack(\$M - 1, Ack(\$M, \$N - 1));
#}

# in our quest for speed, we must get ugly:
# it helps reduce stack frame size a little bit
# from Leif Stensson
sub Ack {
return \$_[0] ? (\$_[1] ? Ack(\$_[0]-1, Ack(\$_[0], \$_[1]-1))
: Ack(\$_[0]-1, 1))
: \$_[1]+1;
}

my \$NUM = \$ARGV[0];
\$NUM = 1 if (\$NUM < 1);
my \$ack = Ack(3, \$NUM);
print "Ack(3,\$NUM): \$ack\n";

```