Skip to content

Instantly share code, notes, and snippets.

@darrenjaworski
Created April 17, 2017 22:23
Show Gist options
  • Save darrenjaworski/0d1d9254740032f0bfdc7b9177ac8395 to your computer and use it in GitHub Desktop.
Save darrenjaworski/0d1d9254740032f0bfdc7b9177ac8395 to your computer and use it in GitHub Desktop.
Ackermann Function - JS
function ackermann(m, n) {
var ans;
if (m === 0) {
ans = n + 1;
} else if (n === 0) {
ans = ackermann(m - 1, 1);
} else {
ans = ackermann(m - 1, ackermann(m, n - 1));
}
return ans;
}
for (var i = 0; i < 5; i++) {
for (var j = 0; j < 5; j++) {
console.log('ackermann (' + i + ', ' + j + ') is ' + ackermann(i,j));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment