Rename functions to be more idiomatic.

This commit is contained in:
2024-12-03 08:53:02 +00:00
parent 5d99f413de
commit 2ee7f6a3d3
5 changed files with 13 additions and 14 deletions

View File

@@ -1,7 +1,7 @@
(** [pair_nums_from_string s] takes a string of two numbers separated by
whitespace and returns the pair of the numbers *)
let pair_nums_from_string s =
match Aoc.nums_from_string s with
let pair_ints_of_string s =
match Aoc.ints_of_string s with
| [ h; h' ] -> (h, h')
| _ -> raise (Invalid_argument "pair_nums_from_string")
@@ -25,8 +25,8 @@ let accumulate = List.fold_left ( + ) 0
(** [lists_from_file fname] Read two lists of integers from [fname] and return
as a pair. *)
let lists_from_file fname =
Aoc.strings_from_file fname |> List.map pair_nums_from_string |> rev_split
let lists_of_file fname =
Aoc.strings_of_file fname |> List.map pair_ints_of_string |> rev_split
let day2401a (a, b) =
List.map2 Aoc.distance1 (List.sort Int.compare a) (List.sort Int.compare b)
@@ -35,5 +35,5 @@ let day2401a (a, b) =
let day2401b (a, b) = List.map (count b) a |> List.map2 ( * ) a |> accumulate
let _ =
Aoc.main lists_from_file
Aoc.main lists_of_file
[ (string_of_int, day2401a); (string_of_int, day2401b) ]