March 03, 2025

Solution for Advent of Code 2018 - Day 6: Chronal Coordinates

Link to the puzzle text

Part 1

In this puzzle we have a list of 2D coordinates. These describe points on an infinite grid. Each cell in the grid is filled with with the nearest point when measured by the Manhattan distance. When two points are the same distance, we do not fill the cell. We should find the largest finite area.

We start with a empty grid. For each field we calculate the distance to each original point and check if it was unique. If yes, we fill the field with the index of the nearest point. Afterwards we count how often each index appears in this grid. We still need to get rid of the infinite areas. For this, we iterate over all border cells. Each index on a border will continue forever, so we have to remove them from the counter.

Finally, only the sizes of finite areas are left and we return the largest one.

Part 2 

In part 2, we should find the number of cells with a sum for all manhattan distances to the original points.

We can simply iterate over the entire grid, calculate the total distance as before and increase a counter if it is below the limit.

Link to my solutions

No comments:

Post a Comment