[Shootout-list] ackermann.ocaml
Christoph Bauer
ich@christoph-bauer.net
Thu, 06 Jan 2005 21:56:18 +0100
Hi,
sorry if you recieve more copies of this email...
This version of ackermann.ocaml is a little bit faster, because it
avoids a tuple construction in the match.
let rec ack m n =
if m = 0 then n+1
else if n = 0 then ack (m-1) 1
else ack (m-1) (ack m (n-1));;
let n = if Array.length Sys.argv > 1 then int_of_string Sys.argv.(1) else 1 in
Printf.printf "Ack(3,%d): %d\n" n (ack 3 n)
best regards,
Christoph Bauer
--
let () = let rec f a w i j = Printf.printf "%.20f\r" a; let a1 = a *. i /. j in
if w then f a1 false (i +. 2.0) j else f a1 true i (j +. 2.0) in f 2.0 false 2.0 1.0