clean up 15.1 implementation a bit
This commit is contained in:
parent
f2f3e497d6
commit
4e57ad4072
16
src/day15.ml
16
src/day15.ml
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user