summaryrefslogtreecommitdiff
path: root/src/3rdparty/squirrel/samples/ackermann.nut
blob: c8d056082c2468908529ba4ddc51a16b197df3eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*
*
* Original Javascript version by David Hedbor(http://www.bagley.org/~doug/shootout/)
*
*/

function Ack(M, N) {
    if (M == 0) return( N + 1 );
    if (N == 0) return( Ack(M - 1, 1) );
    return( Ack(M - 1, Ack(M, (N - 1))) );
}

local n;

if(ARGS.len()!=0) {
   n = ARGS[0].tointeger();
  if(n < 1) n = 1;
} else {
  n = 1;
}
print("n="+n+"\n");
print("Ack(3,"+ n+ "):"+ Ack(3, n));