RosettaCodeData/Task/Ackermann-function/Python/ackermann-function-2.py

11 lines
202 B
Python
Raw Permalink Normal View History

2019-09-12 10:33:56 -07:00
from functools import lru_cache
@lru_cache(None)
2013-04-10 12:38:42 -07:00
def ack2(M, N):
if M == 0:
return N + 1
elif N == 0:
2015-02-20 00:35:01 -05:00
return ack2(M - 1, 1)
2013-04-10 12:38:42 -07:00
else:
2015-02-20 00:35:01 -05:00
return ack2(M - 1, ack2(M, N - 1))