Last active
August 29, 2015 14:04
-
-
Save bradoyler/b10801a21fd72e25d055 to your computer and use it in GitHub Desktop.
Ackermann function: In the 1920s, Wilhelm Ackermann demonstrated a computable function that was not primitive-recursive, settling an important argument in the run-up to the theory of computation. There are several versions of his function, of which the most common is defined over non-negative integers m and n. The function grows very rapidly, ev…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ack(m,n) { | |
return (m == 0) ? | |
n + 1 : | |
(m > 0 && n==0) ? | |
ack(m-1,1) : | |
(m > 0 && n > 0) ? | |
ack(m - 1, ack(m,n-1)) : | |
undefined; | |
} | |
console.log(ack(3,4)); | |
//> 125 | |
// Try ack(4,1); | |
// and you'll get "RangeError: Maximum call stack size exceeded" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ackermann function for GoLang: https://gist.github.com/bradoyler/0d35719fef87916023dd
based on: http://www.eprg.org/computerphile/ackermann.c