-- $Id: ackermann.lua,v 1.5 2000/12/09 20:07:43 doug Exp $
-- http://www.bagley.org/~doug/shootout/
-- contributed by Roberto Ierusalimschy

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

NUM = tonumber((arg and arg[1])) or 1
io.write("Ack(3,", NUM ,"): ", Ack(3,NUM), "\n")