From f61042cb8a06cfd701c6a2308d9b4ef999d57986 Mon Sep 17 00:00:00 2001 From: maxneedspats <84929191+maxneedspats@users.noreply.github.com> Date: Thu, 2 Jun 2022 16:35:26 -0500 Subject: [PATCH] Now an Ackermann function program --- testing.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 testing.py diff --git a/testing.py b/testing.py new file mode 100644 index 0000000..de27f8f --- /dev/null +++ b/testing.py @@ -0,0 +1,17 @@ +# Ackermann function +def ackermann(m, n): + if m == 0: + return n + 1 + elif m > 0 and n == 0: + return ackermann(m - 1, 1) + else: + return ackermann(m - 1, ackermann(m, n - 1)) + +# Sets much higher recursion limit +import sys +sys.setrecursionlimit(2000) + +# Main part, input and print +num1 = int(input("Input m: ")) +num2 = int(input("Input n: ")) +print(ackermann(num1, num2)) \ No newline at end of file