|
@@ -22,7 +22,10 @@ func nearest(coords: seq[Point], point: Point): int =
|
22
|
22
|
distances = coords.map(proc(coord: Point): int = coord.distance(point))
|
23
|
23
|
lowest = min(distances)
|
24
|
24
|
lowest_count = distances.filter(proc (distance: int): bool = distance == lowest).len
|
25
|
|
- if lowest_count == 1: distances.find(lowest) else: -1
|
|
25
|
+ if lowest_count == 1:
|
|
26
|
+ distances.find(lowest)
|
|
27
|
+ else:
|
|
28
|
+ -1
|
26
|
29
|
|
27
|
30
|
func inrange(coords: seq[Point], point: Point): bool = coords.map(proc (coord: Point): int =
|
28
|
31
|
coord.distance(point)).sum < 10000
|
|
@@ -36,7 +39,7 @@ func part1(coords: seq[Point], extents: array[4, int]): int =
|
36
|
39
|
for y in extents[2] .. extents[3]:
|
37
|
40
|
let coord = coords.nearest([x, y])
|
38
|
41
|
if coord != -1:
|
39
|
|
- counts[coord] += 1
|
|
42
|
+ counts[coord].inc
|
40
|
43
|
|
41
|
44
|
# If the area reaches the edge of the grid, it will continue infinitely.
|
42
|
45
|
# Mark that area as excluded.
|