July 05, 2026

Solution for Advent of Code 2018 - Day 25: Four-Dimensional Adventure

Link to the puzzle text

Part 1

In this puzzle, we have a list of 4-dimensional coordinates of stars. Whenever two stars have a manhattan distance of 3 units of less, they belong to the same constellation. This can be transitive, so if stars A and B are close and B and C are close, then A and C are in the same constellation even if they may be more than 3 units apart. We are asked to find the total number of constellations.

We start by a constellation of a single star and then merge all close stars whenever at least they are close enough. This is repeated until this constellation cannot grow any further. In this case we have a finished constellation and we can increment the number of constellations by one.

grown_constellation = {x for x in full_constellation}
for star in full_constellation:
for neighbor in neighbors[star]:
grown_constellation.add(neighbor)
neighbors[star] = set()
full_constellation = grown_constellation 

Part 2

No part 2 for the last day, so were are done for 2018.

Link to my solutions

No comments:

Post a Comment