day 06
chronal coordinates
approach
everything happens inside the bounding box of the given coordinates. for part 1, every cell computes its manhattan distance to each coordinate and takes the closest one, or None on a tie. any coordinate that owns a cell on the edge of the box would grow forever, so it is excluded, and a Counter tallies the cells of the rest.
part 2 sums each cell's distances to all coordinates and counts the cells under 10000.
the file opens with a large "refactor" warning banner. it builds area and count at module level and never prints them, and the largest value in area (the part 1 answer) is left to be read out by hand.
the trick
any region that reaches the edge of the bounding box is infinite, so drop those and only count the rest.
python
def part1grid():
grid={}
#for each point in the grid, calculate manhattan distance with each point, get lowest.
for x in range(x0,x1+1):
for y in range(y0,y1+1):
distances=sorted([(idx,manhattan_distance((x,y),points[idx])) for idx in points],key=lambda x:x[1])
#shares closest dist with two points, not useful.
if distances[0][1]==distances[1][1]:
grid[(x,y)]=None
else:
#else we get the index of the closest point
grid[(x,y)]=distances[0][0]
return grid