-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathackerman.py
More file actions
37 lines (31 loc) · 762 Bytes
/
Copy pathackerman.py
File metadata and controls
37 lines (31 loc) · 762 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import sys
# sys.setrecursionlimit(10**9)
# print(sys.getrecursionlimit())
doot = 0
# def ackermann(m,n):
# assert m >= 0, 'doot'
# assert n >= 0, 'doot'
# if m == 0:
# return n + 1
# elif n == 0:
# return ackermann(m - 1, 1)
# else:
# return ackermann(m - 1, ackermann(m, n - 1))
def ackermann(m, n):
global doot
try:
doot += 1
if m == 0:
# BASE CASE
return n + 1
elif m > 0 and n == 0:
# RECURSIVE CASE
return ackermann(m - 1, 1)
elif m > 0 and n > 0:
# RECURSIVE CASE
return ackermann(m - 1, ackermann(m, n - 1))
except:
pass
# print(doot)
print(ackermann(4, 1))
# print(doot)