challenge-codinggame/la-descente/code.ml

39 lines
778 B
OCaml
Raw Normal View History

2016-07-26 12:21:15 +00:00
let rec read_mountains n =
let mountainh = int_of_string (input_line stdin) in
if n < 1 then []
else mountainh :: (read_mountains (n-1))
;;
let c = ref 0 in
prerr_endline "Start" ;
(** game loop *)
while true do
c := !c + 1 ;
string_of_int !c
|> fun str -> "tour = " ^ str
|> prerr_endline ;
let mountains = read_mountains 7
in
let target =
mountains
|> List.mapi (fun idx value -> (value, idx))
|> List.sort (fun (value1, idx1) (value2, idx2) -> Pervasives.compare value1 value2 )
|> List.hd
|> fun (idx, value) -> idx
in
let target_str = string_of_int target
in
prerr_endline ("target = " ^ target_str);
print_endline target_str ;
();
done;