tack.nim 370 B

12345678910111213141516171819202122
  1. discard """
  2. file: "tack.nim"
  3. output: "125"
  4. """
  5. # the Ackermann function
  6. proc ack(x, y: int): int =
  7. if x != 0:
  8. if y != 0:
  9. return ack(x-1, ack(x, y-1))
  10. return ack(x-1, 1)
  11. else:
  12. return y + 1
  13. # if x == 0: return y + 1
  14. # elif y == 0: return ack(x-1, 1)
  15. # else: return ack(x-1, ack(x, y-1))
  16. # echo(ack(0, 0))
  17. write(stdout, ack(3, 4)) #OUT 125