Skip to content

Instantly share code, notes, and snippets.

@clintval
Last active August 29, 2015 14:08
Show Gist options
  • Save clintval/3f902e10476c53f74d17 to your computer and use it in GitHub Desktop.
Save clintval/3f902e10476c53f74d17 to your computer and use it in GitHub Desktop.
Ackermann Function
#!/usr/bin/python
# pylint: disable=C0103
"""
A function which outputs the Ackermann values for M and N
Citation: Weisstein, Eric W. "Ackermann Function." From MathWorld--A Wolfram Web Resource.
http://mathworld.wolfram.com/AckermannFunction.html
"""
M = 3
N = 3
I = [0]
def ack(m, n):
"""Ackermann's Function"""
I[0] += 1
if m == 0:
return n + 1
elif n == 0:
return ack(m - 1, 1)
else:
return ack(m - 1, ack(m, n - 1))
print "Ackermann Value for {} and {}: {}".format(M, N, ack(3, 3))
print "Iterations: {}".format(I)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment