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

11 lines
188 B
Python
Raw Normal View History

2026-02-01 16:33:20 -08:00
from functools import cache
2023-07-01 11:58:00 -04:00
2026-02-01 16:33:20 -08:00
@cache
2023-07-01 11:58:00 -04:00
def ack2(M, N):
if M == 0:
return N + 1
elif N == 0:
return ack2(M - 1, 1)
else:
return ack2(M - 1, ack2(M, N - 1))