add pair_of_list helper function
This commit is contained in:
parent
883d16a3a3
commit
8a9648ff3e
2 changed files with 5 additions and 4 deletions
|
@ -41,10 +41,12 @@ let outcome me oponent =
|
||||||
| 1 | -2 -> Win
|
| 1 | -2 -> Win
|
||||||
| _ -> Draw
|
| _ -> Draw
|
||||||
|
|
||||||
|
open Utils
|
||||||
|
|
||||||
let solve f l = l
|
let solve f l = l
|
||||||
|> List.map (fun line -> line
|
|> List.map (fun line -> line
|
||||||
|> String.split_on_char ' '
|
|> String.split_on_char ' '
|
||||||
|> (fun l -> (List.hd l, List.tl l |> List.hd))
|
|> pair_of_list
|
||||||
|> f
|
|> f
|
||||||
|> (fun (oponent, me) -> ((outcome me oponent) |> int_of_outcome) + int_of_choice me))
|
|> (fun (oponent, me) -> ((outcome me oponent) |> int_of_outcome) + int_of_choice me))
|
||||||
|> List.fold_left (+) 0
|
|> 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)
|
(choice_of_string oponent_s, outcome_of_string outcome_s)
|
||||||
|> (fun (oponent, outcome) -> (oponent, (choice_of_outcome oponent outcome))))
|
|> (fun (oponent, outcome) -> (oponent, (choice_of_outcome oponent outcome))))
|
||||||
|
|
||||||
open Utils
|
|
||||||
|
|
||||||
let _ = "\n1: " ^ (string_of_int (read_file "bin/d2/input.txt" |> d2_1)) ^
|
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
|
"\n2: " ^ (string_of_int (read_file "bin/d2/input.txt" |> d2_2)) |> print_endline
|
||||||
|
|
|
@ -18,9 +18,10 @@ let set_of_string str =
|
||||||
aux str ((String.length str) - 1) CS.empty
|
aux str ((String.length str) - 1) CS.empty
|
||||||
|
|
||||||
let map_pair f (a, b) = (f a, f b)
|
let map_pair f (a, b) = (f a, f b)
|
||||||
|
|
||||||
let curry f x y = f (x, y)
|
let curry f x y = f (x, y)
|
||||||
let uncurry 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 uncurry3 f (x, y, z) = f x y z
|
||||||
|
|
||||||
let swap x y = y x
|
let swap x y = y x
|
||||||
|
|
||||||
|
let pair_of_list l = (List.hd l, List.tl l |> List.hd)
|
||||||
|
|
Loading…
Reference in a new issue