Skip to content

Instantly share code, notes, and snippets.

@bradoyler
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bradoyler/b10801a21fd72e25d055 to your computer and use it in GitHub Desktop.
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…
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"
@bradoyler
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment