/* The Computer Language Shootout
   http://shootout.alioth.debian.org/

   contributed by Nicolas Cannasse
*/
ack = function(x,y) {
	if( x == 0 ) return y + 1;
	if( y == 0 ) return ack(x - 1,1);
	return ack(x - 1,ack(x,y - 1));
}

fib = function(n) {
	if( n < 2 ) return 1;
	return fib(n-2) + fib(n-1);
}

fib_fp = function(n) {
	if( n < 2.0 ) return 1.0;
	return fib_fp(n - 2.0) + fib_fp(n - 1.0);
}

tak = function(x,y,z) {
	if( y >= x ) return z;
	return tak(tak(x-1,y,z),tak(y-1,z,x),tak(z-1,x,y));
}

tak_fp = function(x,y,z) {
	if( y >= x ) return z;
	return tak_fp(tak_fp(x-1.0,y,z),tak_fp(y-1.0,z,x),tak_fp(z-1.0,x,y));
}

var n = $int($loader.args[0]);
if( n == null ) n = 4;
n -= 1;

$print("Ack(3,",n + 1,"): ",ack(3,n + 1),"\n");
$print("Fib(",n + 28.0,".0): ",fib_fp(n + 28.0),".0\n");
$print("Tak(",3*n,",",2*n,",",n,"): ",tak(3*n,2*n,n),"\n");
$print("Fib(",3,"): ",fib(3),"\n");
$print("Tak(3.0,2.0,1.0): ",tak_fp(3.0,2.0,1.0),".0\n");
