diff --git a/bin/d2/main.ml b/bin/d2/main.ml index 4eb449d..262d05a 100644 --- a/bin/d2/main.ml +++ b/bin/d2/main.ml @@ -41,10 +41,12 @@ let outcome me oponent = | 1 | -2 -> Win | _ -> Draw +open Utils + let solve f l = l |> List.map (fun line -> line |> String.split_on_char ' ' - |> (fun l -> (List.hd l, List.tl l |> List.hd)) + |> pair_of_list |> f |> (fun (oponent, me) -> ((outcome me oponent) |> int_of_outcome) + int_of_choice me)) |> List.fold_left (+) 0 @@ -56,7 +58,5 @@ let d2_2 = solve (fun (oponent_s, outcome_s) -> (choice_of_string oponent_s, outcome_of_string outcome_s) |> (fun (oponent, outcome) -> (oponent, (choice_of_outcome oponent outcome)))) -open Utils - let _ = "\n1: " ^ (string_of_int (read_file "bin/d2/input.txt" |> d2_1)) ^ "\n2: " ^ (string_of_int (read_file "bin/d2/input.txt" |> d2_2)) |> print_endline diff --git a/lib/utils.ml b/lib/utils.ml index 08d22ad..132e49e 100644 --- a/lib/utils.ml +++ b/lib/utils.ml @@ -18,9 +18,10 @@ let set_of_string str = aux str ((String.length str) - 1) CS.empty let map_pair f (a, b) = (f a, f b) - let curry f x y = f (x, y) let uncurry f (x, y) = f x y let uncurry3 f (x, y, z) = f x y z let swap x y = y x + +let pair_of_list l = (List.hd l, List.tl l |> List.hd)