How to resolve the algorithm Ackermann function step by step in the Objeck programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Ackermann function step by step in the Objeck 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 Objeck programming language
Source code in the objeck programming language
class Ackermann {
function : Main(args : String[]) ~ Nil {
for(m := 0; m <= 3; ++m;) {
for(n := 0; n <= 4; ++n;) {
a := Ackermann(m, n);
if(a > 0) {
"Ackermann({$m}, {$n}) = {$a}"->PrintLine();
};
};
};
}
function : Ackermann(m : Int, n : Int) ~ Int {
if(m > 0) {
if (n > 0) {
return Ackermann(m - 1, Ackermann(m, n - 1));
}
else if (n = 0) {
return Ackermann(m - 1, 1);
};
}
else if(m = 0) {
if(n >= 0) {
return n + 1;
};
};
return -1;
}
}
You may also check:How to resolve the algorithm Zebra puzzle step by step in the Racket programming language
You may also check:How to resolve the algorithm Variadic function step by step in the Euphoria programming language
You may also check:How to resolve the algorithm Universal Turing machine step by step in the SequenceL programming language
You may also check:How to resolve the algorithm Hello world/Newline omission step by step in the Pixilang programming language
You may also check:How to resolve the algorithm Sieve of Eratosthenes step by step in the Xojo programming language