Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
25
Task/Ackermann-function/Python/ackermann-function-5.py
Normal file
25
Task/Ackermann-function/Python/ackermann-function-5.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
from collections import deque
|
||||
|
||||
def ack_ix(m, n):
|
||||
"Paddy3118's iterative with optimisations on m"
|
||||
|
||||
stack = deque([])
|
||||
stack.extend([m, n])
|
||||
|
||||
while len(stack) > 1:
|
||||
n, m = stack.pop(), stack.pop()
|
||||
|
||||
if m == 0:
|
||||
stack.append(n + 1)
|
||||
elif m == 1:
|
||||
stack.append(n + 2)
|
||||
elif m == 2:
|
||||
stack.append(2*n + 3)
|
||||
elif m == 3:
|
||||
stack.append(2**(n + 3) - 3)
|
||||
elif n == 0:
|
||||
stack.extend([m-1, 1])
|
||||
else:
|
||||
stack.extend([m-1, m, n-1])
|
||||
|
||||
return stack[0]
|
||||
Loading…
Add table
Add a link
Reference in a new issue