clean up 15.1 implementation a bit

This commit is contained in:
rmanseau 2023-11-27 13:45:32 -08:00
parent f2f3e497d6
commit 4e57ad4072
No known key found for this signature in database
GPG Key ID: 060BE2D43CFAB17A

View File

@ -101,19 +101,15 @@ let solve_part_1 lines scan_y =
(Iter.map (fun n -> n - scan_y) n_slope_consts)
|> Iter.sort_uniq ~cmp:Int.compare
in
let check x = could_be_beacon sensors false @@ Vec2.of_tuple (x, scan_y) in
let rec count_not_beacons count xs =
match xs with
| x :: next :: rest ->
let intersection =
if could_be_beacon sensors false @@ Vec2.of_tuple (x, scan_y) then 0 else 1
in
(* if there is a region between this intersection and the next, the value
of could_be_beacon is the same for each point within it. *)
let region =
if x + 1 < next && (could_be_beacon sensors false @@ Vec2.of_tuple (x + 1, scan_y))
then 0
else next - (x + 1)
in
(* if there is a region [x+1, next), the value of check
is the same for each point within it. intersection points
must be checked separately from the regions between them *)
let intersection = if check x then 0 else 1 in
let region = if x + 1 < next && check (x + 1) then 0 else next - (x + 1) in
count_not_beacons (count + intersection + region) (next :: rest)
| _ -> count
in