Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,3 @@
def ack1(M, N):
return (N + 1) if M == 0 else (
ack1(M-1, 1) if N == 0 else ack1(M-1, ack1(M, N-1)))

View file

@ -0,0 +1,10 @@
from functools import lru_cache
@lru_cache(None)
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))

View file

@ -0,0 +1,10 @@
>>> import sys
>>> sys.setrecursionlimit(3000)
>>> ack1(0,0)
1
>>> ack1(3,4)
125
>>> ack2(0,0)
1
>>> ack2(3,4)
125

View file

@ -0,0 +1,6 @@
def ack2(M, N):
return (N + 1) if M == 0 else (
(N + 2) if M == 1 else (
(2*N + 3) if M == 2 else (
(8*(2**N - 1) + 5) if M == 3 else (
ack2(M-1, 1) if N == 0 else ack2(M-1, ack2(M, N-1))))))

View 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]