tack.nim 368 B

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