Skip to content

Instantly share code, notes, and snippets.

@ejmurray
Created February 19, 2015 21:34
Show Gist options
  • Save ejmurray/521c2682c03eaa3e5f31 to your computer and use it in GitHub Desktop.
Save ejmurray/521c2682c03eaa3e5f31 to your computer and use it in GitHub Desktop.
"""This module contains code from
Think Python by Allen B. Downey
http://thinkpython.com
Copyright 2012 Allen B. Downey
License: GNU GPLv3 http://www.gnu.org/licenses/gpl.html
"""
def ackermann(m, n):
"""Computes the Ackermann function A(m, n)
See http://en.wikipedia.org/wiki/Ackermann_function
n, m: non-negative integers
"""
if m == 0:
return n+1
if n == 0:
return ackermann(m-1, 1)
return ackermann(m-1, ackermann(m, n-1))
print (ackermann(3, 4))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment