I just came across the Ackermann–Péter function a few weeks ago, found it to be very interesting, and decided to write a simple implementation of it in a favorite programming language of mine.
def ackermann_peter_10(m, n):
assert isinstance(m, int) and m >= 0, 'm is unacceptable'
assert isinstance(n, int) and n >= 0, 'n is unacceptable'
stack = []
while True:
if not m:
if not stack:
return n + 1
m, n = stack.pop(), n + 1
elif not n:
m, n = m - 1, 1
else:
stack.append(m - 1)
n -= 1
Can you refactor ackermann_peter_10
any further? It surprised me to see how similar the code is to another version found on Stack Overflow Stack Overflow.
Reference: Simple loop Ackermann function Simple loop Ackermann function
I just came across the Ackermann–Péter function a few weeks ago, found it to be very interesting, and decided to write a simple implementation of it in a favorite programming language of mine.
def ackermann_peter_10(m, n):
assert isinstance(m, int) and m >= 0, 'm is unacceptable'
assert isinstance(n, int) and n >= 0, 'n is unacceptable'
stack = []
while True:
if not m:
if not stack:
return n + 1
m, n = stack.pop(), n + 1
elif not n:
m, n = m - 1, 1
else:
stack.append(m - 1)
n -= 1
Can you refactor ackermann_peter_10
any further? It surprised me to see how similar the code is to another version found on Stack Overflow.
Reference: Simple loop Ackermann function
I just came across the Ackermann–Péter function a few weeks ago, found it to be very interesting, and decided to write a simple implementation of it in a favorite programming language of mine.
def ackermann_peter_10(m, n):
assert isinstance(m, int) and m >= 0, 'm is unacceptable'
assert isinstance(n, int) and n >= 0, 'n is unacceptable'
stack = []
while True:
if not m:
if not stack:
return n + 1
m, n = stack.pop(), n + 1
elif not n:
m, n = m - 1, 1
else:
stack.append(m - 1)
n -= 1
Can you refactor ackermann_peter_10
any further? It surprised me to see how similar the code is to another version found on Stack Overflow.
Reference: Simple loop Ackermann function
Can you refactor this Ackermann function any further?
I just came across the Ackermann–Péter function a few weeks ago, found it to be very interesting, and decided to write a simple implementation of it in a favorite programming language of mine.
def ackermann_peter_10(m, n):
assert isinstance(m, int) and m >= 0, 'm is unacceptable'
assert isinstance(n, int) and n >= 0, 'n is unacceptable'
stack = []
while True:
if not m:
if not stack:
return n + 1
m, n = stack.pop(), n + 1
elif not n:
m, n = m - 1, 1
else:
stack.append(m - 1)
n -= 1
can you refactor ackermann_peter_10
any further?Can you refactor ackermann_peter_10
any further? It surprised me to see how similar the code is to another version found on Stack Overflow.
Reference: Simple loop Ackermann function
I just came across the Ackermann–Péter function a few weeks ago, found it to be very interesting, and decided to write a simple implementation of it in a favorite programming language of mine.
def ackermann_peter_10(m, n):
assert isinstance(m, int) and m >= 0, 'm is unacceptable'
assert isinstance(n, int) and n >= 0, 'n is unacceptable'
stack = []
while True:
if not m:
if not stack:
return n + 1
m, n = stack.pop(), n + 1
elif not n:
m, n = m - 1, 1
else:
stack.append(m - 1)
n -= 1
can you refactor ackermann_peter_10
any further? It surprised me to see how similar the code is to another version found on Stack Overflow.
Reference: Simple loop Ackermann function
I just came across the Ackermann–Péter function a few weeks ago, found it to be very interesting, and decided to write a simple implementation of it in a favorite programming language of mine.
def ackermann_peter_10(m, n):
assert isinstance(m, int) and m >= 0, 'm is unacceptable'
assert isinstance(n, int) and n >= 0, 'n is unacceptable'
stack = []
while True:
if not m:
if not stack:
return n + 1
m, n = stack.pop(), n + 1
elif not n:
m, n = m - 1, 1
else:
stack.append(m - 1)
n -= 1
Can you refactor ackermann_peter_10
any further? It surprised me to see how similar the code is to another version found on Stack Overflow.
Reference: Simple loop Ackermann function
- 8.8k
- 2
- 31
- 69