(* * $Id: nestedloop.ocaml,v 1.7 2001/06/27 11:37:53 doug Exp $ * http://www.bagley.org/~doug/shootout/ * based on code from Florian Hars and Markus Mottl *) let _ = let n = try int_of_string Sys.argv.(1) with Invalid_argument _ -> 1 in let rec loopF x = function 0 -> x | i -> loopF (x+1) (i-1) in let rec loopE x = function 0 -> x | i -> loopE (loopF x n) (i-1) in let rec loopD x = function 0 -> x | i -> loopD (loopE x n) (i-1) in let rec loopC x = function 0 -> x | i -> loopC (loopD x n) (i-1) in let rec loopB x = function 0 -> x | i -> loopB (loopC x n) (i-1) in let rec loopA x = function 0 -> x | i -> loopA (loopB x n) (i-1) in Printf.printf "%d\n" (loopA 0 n)