Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / metrics / jint / sunspider / controlflow-recursive.js
1 // The Computer Language Shootout
2 // http://shootout.alioth.debian.org/
3 // contributed by Isaac Gouy
4
5 function ack(m,n){
6    if (m==0) { return n+1; }
7    if (n==0) { return ack(m-1,1); }
8    return ack(m-1, ack(m,n-1) );
9 }
10
11 function fib(n) {
12     if (n < 2){ return 1; }
13     return fib(n-2) + fib(n-1);
14 }
15
16 function tak(x,y,z) {
17     if (y >= x) return z;
18     return tak(tak(x-1,y,z), tak(y-1,z,x), tak(z-1,x,y));
19 }
20
21 /* BEGIN LOOP */
22 for ( var i = 3; i <= 5; i++ ) {
23     ack(3,i);
24     fib(17.0+i);
25     tak(3*i+3,2*i+2,i+1);
26 }
27 /* END LOOP */