How to resolve the algorithm Ackermann function step by step in the Jsish programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Ackermann function step by step in the Jsish programming language
Table of Contents
Problem Statement
The Ackermann function is a classic example of a recursive function, notable especially because it is not a primitive recursive function. It grows very quickly in value, as does the size of its call tree.
The Ackermann function is usually defined as follows:
Its arguments are never negative and it always terminates.
Write a function which returns the value of
A ( m , n )
{\displaystyle A(m,n)}
. Arbitrary precision is preferred (since the function grows so quickly), but not required.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Ackermann function step by step in the Jsish programming language
Source code in the jsish programming language
/* Ackermann function, in Jsish */
function ack(m, n) {
return m === 0 ? n + 1 : ack(m - 1, n === 0 ? 1 : ack(m, n - 1));
}
if (Interp.conf('unitTest')) {
Interp.conf({maxDepth:4096});
; ack(1,3);
; ack(2,3);
; ack(3,3);
; ack(1,5);
; ack(2,5);
; ack(3,5);
}
/*
=!EXPECTSTART!=
ack(1,3) ==> 5
ack(2,3) ==> 9
ack(3,3) ==> 61
ack(1,5) ==> 7
ack(2,5) ==> 13
ack(3,5) ==> 253
=!EXPECTEND!=
*/
You may also check:How to resolve the algorithm HTTPS/Client-authenticated step by step in the Mathematica / Wolfram Language programming language
You may also check:How to resolve the algorithm Abundant odd numbers step by step in the Maple programming language
You may also check:How to resolve the algorithm Reflection/List methods step by step in the Tcl programming language
You may also check:How to resolve the algorithm Create a file step by step in the Elena programming language
You may also check:How to resolve the algorithm Strip a set of characters from a string step by step in the Sed programming language