Ackermann Function

Algorithm:

The following procedure computes a mathematical function called the Ackermann function (Exercise 1.10 from SICP):

f(x,y) =

For small x, the Ackermann function is equivalent to the following functions:

The Ackermann function is known for being very fast to compute.

Code:

def functionAckermann(x: Int, y: Int): Int =
  if y == 0 then 0
  else if x == 0 then 2 * y
  else if y == 1 then 2
  else functionAckermann(x - 1, functionAckermann(x, y - 1))

functionAckermann(3, 3)
// 65536

References: