Skip to content

Commit

Permalink
added Ackerman function
Browse files Browse the repository at this point in the history
  • Loading branch information
bntshakya committed Oct 20, 2023
1 parent 0315c8a commit 7b433c4
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Recursive/Ackerman.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @function ackermann
* @description function to calculate the Ackermann function using recursion
* @param {integer} m - first number
* @param {integer} n - second number
* @returns {integer} - result of the Ackermann function
* @see https://en.wikipedia.org/wiki/Ackermann_function
* @example ackermann(3, 4) = 125
*/


function ackermann(m, n) {
if (m === 0) {
return n + 1;
}
if (m > 0 && n === 0) {
return ackermann(m - 1, 1);
}
if (m > 0 && n > 0) {
return ackermann(m - 1, ackermann(m, n - 1));
}
}

0 comments on commit 7b433c4

Please sign in to comment.