Make ints_of_string generic and move to lib.

This commit is contained in:
2024-12-05 15:43:18 +00:00
parent 3052751eb6
commit c6fb838463
3 changed files with 8 additions and 8 deletions

View File

@@ -39,13 +39,12 @@ let rec is_page_order_valid m pages =
encountering an empty line. Returns a pair [(rule_map, tail)].
[tail] starts the line after the empty line. *)
let parse_rules =
let re = Str.regexp_string "|" in
let m = Hashtbl.create 17 in
let rec impl = function
| "" :: t -> (m, t)
| [] -> failwith "parse_rules.impl"
| h :: t -> (
match List.map int_of_string (Str.split re h) with
match Aoc.ints_of_string ~sep:"|" h with
| [ a; b ] ->
add_rule a b m;
impl t
@@ -55,10 +54,9 @@ let parse_rules =
(** [parse_page_orders lst] parses a list of page orders. *)
let parse_page_orders =
let re = Str.regexp_string "," in
let rec impl acc = function
| [] -> acc
| h :: t -> impl (List.map int_of_string (Str.split re h) :: acc) t
| h :: t -> impl (Aoc.ints_of_string ~sep:"," h :: acc) t
in
impl []