Created
September 9, 2020 09:40
-
-
Save multun/f7b8bc3e6e679345a404657140b65042 to your computer and use it in GitHub Desktop.
Fast ackermann
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import lru_cache | |
@lru_cache(maxsize=1024) | |
def kn(a, b, order): | |
assert order >= 1 | |
if order == 1: | |
return a ** b | |
sub_order = order - 1 | |
res = a | |
for i in range(order): | |
res = kn(res, b, sub_order) | |
return res | |
def conway(p, q, r): | |
return kn(p, q, r) | |
def ackermann(m, n): | |
return conway(2, n + 3, m - 2) - 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment