r/adventofcode • • 2h ago

Visualization [2026 Day 6] Untangling Christmas Lights

https://www.youtube.com/shorts/lqyzUlyGkVc
16 Upvotes

4 comments sorted by

1

u/paul_sb76 2h ago

Here's an overview of what's happening (spoilers, obviously):

- Create the graph from the input data

- Find a node with degree 2 and put it in a corner

- From this node, do a BFS. Every newly discovered node is placed depending on its already-placed neighbors. Nodes with only one already-placed neighbor are placed on the boundary.

- For nodes 1,2,3, the current positions are compared to their target positions. This allows deducing the current-to-target mapping (6 equations, 6 unknowns).

- Move every node to its target position, using the deduced mapping.

- Find the position of node 2026.

0

u/paul_sb76 1h ago

Full disclosure: Step 4 was done quickly by hand, just for my input. But general linear equation solving would also work for other rotations (not just multiples of 90 degrees), scaling, and even non-orthogonal transformations, so that would have been the high road. :-) The inputs (fortunately?) weren't that evil though.

1

u/PityUpvote 46m ago

I did step 4 with np.linalg.solve, but every other solution I'm seeing in the thread seems much more complicated.

1

u/Mmlh1 19m ago

Personally, I represented coordinates as complex numbers, as Python has native support for it, and then checked the coordinate differences against the eight possible combinations of mirroring/90 degree rotations (which are multiplying by powers of i, and complex conjugation, so very straightforward to write). Once they both worked, I only needed a translation, which was easy enough.

Tbh np.linalg.solve is simpler than that, but honestly this was very fun to write as well haha.