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