The Ackermann function is a classic example of a recursive function, notable especially because it is not a primitive recursive function. It grows very quickly in value, as does the size of its call tree.
The Ackermann function is usually defined as follows:
$$A(m, n) = \begin{cases} n+1 & \mbox{if } m = 0 \\ A(m-1, 1) & \mbox{if } m > 0 \mbox{ and } n = 0 \\ A(m-1, A(m, n-1)) & \mbox{if } m > 0 \mbox{ and } n > 0. \end{cases}$$Its arguments are never negative and it always terminates. Write a function which returns the value of $A(m, n)$. Arbitrary precision is preferred (since the function grows so quickly), but not required.
ack
is a function.
testString: assert(typeof ack === 'function', 'ack
is a function.');
- text: ack(0, 0)
should return 1.
testString: assert(ack(0, 0) === 1, 'ack(0, 0)
should return 1.');
- text: ack(1, 1)
should return 3.
testString: assert(ack(1, 1) === 3, 'ack(1, 1)
should return 3.');
- text: ack(2, 5)
should return 13.
testString: assert(ack(2, 5) === 13, 'ack(2, 5)
should return 13.');
- text: ack(3, 3)
should return 61.
testString: assert(ack(3, 3) === 61, 'ack(3, 3)
should return 61.');
```