Use same printer for both parts

We want to change Aoc.main to take a single printer parameter to
simplify the run process.
This commit is contained in:
2024-12-24 20:28:52 +00:00
parent 030fd73bab
commit 43b47b2a34
2 changed files with 10 additions and 14 deletions

View File

@@ -104,12 +104,12 @@ let find_route_length count grid =
let part1 count rocks =
match find_route_length count rocks with
| None -> failwith "part1"
| Some (cost, _) -> cost
| Some (cost, _) -> string_of_int cost
(** [part2 start_count grid] returns the location of the first rock to fall into
[grid] which makes it impossible to get from the top-left to bottom-right.
*)
let part2 start_count grid =
let part2 width start_count grid =
(* Implementation notes:
We do this by binary search in impl. The left_count is a known count of
@@ -137,16 +137,11 @@ let part2 start_count grid =
let count = impl start_count (1 + count_rocks 0 0) in
match Array.find_index (( = ) (count - 1)) grid.grid with
| None -> failwith "part2"
| Some idx -> idx
(** [string_of_idx width idx] prints the (x, y) location for a given index in a
grid. *)
let string_of_idx width idx =
Printf.sprintf "%d,%d" (idx mod width) (idx / width)
| Some idx -> Printf.sprintf "%d,%d" (idx mod width) (idx / width)
(** Width of grid *)
let width = 71
let _ =
Aoc.main (grid_of_file width)
[ (string_of_int, part1 1024); (string_of_idx width, part2 1024) ]
[ (Fun.id, part1 1024); (Fun.id, part2 width 1024) ]