[Shootout-list] ackermann.ocaml

Bauer, Christoph Christoph.Bauer at lms-gmbh.de
Sun Apr 23 22:57:14 UTC 2006


Hi, 

this version 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) 

regards, 
Christoph Bauer 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.alioth.debian.org/pipermail/shootout-list/attachments/20060423/0b8f46c7/attachment.htm


More information about the Shootout-list mailing list