Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
| Download

📚 The CoCalc Library - books, templates and other resources

Views: 96171
License: OTHER
1
"""This module contains a code example related to
2
3
Think Python, 2nd Edition
4
by Allen Downey
5
http://thinkpython2.com
6
7
Copyright 2015 Allen Downey
8
9
License: http://creativecommons.org/licenses/by/4.0/
10
"""
11
12
from __future__ import print_function, division
13
14
15
def ackermann(m, n):
16
"""Computes the Ackermann function A(m, n)
17
18
See http://en.wikipedia.org/wiki/Ackermann_function
19
20
n, m: non-negative integers
21
"""
22
if m == 0:
23
return n+1
24
if n == 0:
25
return ackermann(m-1, 1)
26
return ackermann(m-1, ackermann(m, n-1))
27
28
29
print(ackermann(3, 4))
30
31