Skip to main content
Code Review

Return to Question

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

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

Tweeted twitter.com/StackCodeReview/status/694098580760612865
edited title
Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

Can you refactor this Ackermann function any further?

improved formatting from previous edit
Source Link

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

Awesome work, but ultimately unnecessary and destracts from your actual, current code.
Source Link
Kaz
  • 8.8k
  • 2
  • 31
  • 69
Loading
Source Link
Loading
lang-py

AltStyle によって変換されたページ (->オリジナル) /