diff --git a/bin/day2417.ml b/bin/day2417.ml index cd84e35..153d58e 100644 --- a/bin/day2417.ml +++ b/bin/day2417.ml @@ -129,7 +129,8 @@ let rec execute_until_halted vm = | false -> execute_until_halted (execute_insn vm) (** [string_of_ouput vm] gives the output of [vm]. *) -let string_of_output vm = +let part1 vm = + let vm = execute_until_halted vm in List.rev vm.out |> List.map string_of_int |> String.concat "," (** [scan_digit acc ip vm] updates the acc for A so that the output of running @@ -159,8 +160,8 @@ let scan_all vm = impl 0 (Array.length vm.code - 1) (** [string_of_a vm] returns the A register of [vm]. *) -let string_of_a vm = string_of_int vm.a +let part2 vm = + let vm = scan_all vm in + string_of_int vm.a -let _ = - Aoc.main vm_of_file - [ (string_of_output, execute_until_halted); (string_of_a, scan_all) ] +let _ = Aoc.main vm_of_file [ (Fun.id, part1); (Fun.id, part2) ] diff --git a/bin/day2418.ml b/bin/day2418.ml index 3e8b355..8c457f5 100644 --- a/bin/day2418.ml +++ b/bin/day2418.ml @@ -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) ]