Last active
August 29, 2015 14:08
-
-
Save clintval/3f902e10476c53f74d17 to your computer and use it in GitHub Desktop.
Ackermann Function
This file contains 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
#!/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