A função Ackermann é um exemplo clássico de uma função recursiva, notável principalmente porque não é uma função recursiva primitiva. Ela cresce muito rapidamente em valor, assim como o tamanho de sua árvore de chamadas.
A função Ackermann é geralmente definida da seguinte forma:
$$ A (m, n) = \ begin {casos} n + 1 & \ mbox {if} m = 0 \\ A (m-1, 1) e \ mbox {if} m> 0 \ mbox {e} n = 0 \\ A (m-1, A (m, n-1)) e \ mbox {if} m> 0 \ mbox {e} n> 0. \ end {cases} $$Seus argumentos nunca são negativos e sempre terminam. Escreva uma função que retorne o valor de $ A (m, n) $. Precisão arbitrária é preferida (já que a função cresce tão rapidamente), mas não é necessária.
ack
é uma função.
testString: 'assert(typeof ack === "function", "ack
is a function.");'
- text: 'ack(0, 0)
deve retornar 1.'
testString: 'assert(ack(0, 0) === 1, "ack(0, 0)
should return 1.");'
- text: 'ack(1, 1)
deve retornar 3.'
testString: 'assert(ack(1, 1) === 3, "ack(1, 1)
should return 3.");'
- text: 'ack(2, 5)
deve retornar 13.'
testString: 'assert(ack(2, 5) === 13, "ack(2, 5)
should return 13.");'
- text: 'ack(3, 3)
deve retornar 61.'
testString: 'assert(ack(3, 3) === 61, "ack(3, 3)
should return 61.");'
```