Now an Ackermann function program
This commit is contained in:
commit
f61042cb8a
1 changed files with 17 additions and 0 deletions
17
testing.py
Normal file
17
testing.py
Normal file
|
@ -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))
|
Loading…
Reference in a new issue