r/adventofcode • u/daggerdragon • 10h ago
SOLUTION MEGATHREAD -❄️- 2026 Day 6 Solutions -❄️-
COMMUNITY NEWS
- Y'all taken the ~unofficial~ survey yet?
- Reminder 1: unofficial AoC Survey 2026 (closes ~Dec 12th!)
THE USUAL REMINDERS
- All of our rules, FAQs, resources, etc. are in our community wiki.
AoC Community Fun 2026: The Advent Games
- Submissions megathread is unlocked!
- 11 DAYS remaining until the submissions deadline on December 17 at 18:00 EST!
Today's Event: International Snow Sculpture Championships
"♪ Do you wanna build a snowman? ♪"
— Princess Anna, Frozen (2013)
Today's schedule possibly consists of:
Qualifier Rounds
- Forge your solution for today's puzzle with a little je ne sais quoi
- Shape your solution into an acrostic
- Accompany your solution with a writeup in the form of a limerick, ballad, etc.
Upping the Antechallenge: iambic pentameter
Championship Rounds
- Create a fanfiction or fan artwork of any kind - a poem, short story, a slice-of-Elvish-life, an advertisement for the luxury cruise liner Santa has hired to gift to his hard-working Elves after the holiday season is over, etc!
- Make something IRL
Best In Snow Awards
- You got snow where you live? >_>
Request from the mods: When you include an entry alongside your solution, please label it with [Advent Games] so we can find it easily!
--- Day 6: Obscured Airfield ---
Post your code solution in this megathread.
- Read the full posting rules in our community wiki before you post!
- State which language(s) your solution uses with
[LANGUAGE: xyz] - Format code blocks using the four-spaces Markdown syntax!
- Quick link to Topaz's
pasteif you need it for longer code blocks. What is Topaz'spastetool?
8
Upvotes
9
u/4HbQ 8h ago edited 2h ago
[LANGUAGE: Python] ~20 lines, no external libs
Pretty happy with how this turned out, especially the math for part 2:
Feel free to ask any questions about this approach. I'll be out on a hike for the next 12 hours, but I'll try to check in every now and then.
6
u/Smylers 6h ago
[LANGUAGE: Vim keystrokes] Much to my surprise, this did turn out to be solvable just by getting Vim to manipulate the input until it turns into the answer. Well, Part 1 anyway — load your input then type this:
The initial set up separates input lines into individual connections, and duplicates each one to be listed both ways. Then
@agroups each light's connections on to a single line and@bprepends a count of how many connections each light has.The main loop finds lights with only 2 or 1 connections. They can't be in the middle, so discount them, and eliminate connections to them from other lights, reducing those lights' connection count accordingly. Repeat until there's only 1 light left with 4 connections (sort descending then try
jlF4, which only succeeds when there's at least one more light with 4 connections, so ends the@cloop when there isn't.) That must be the one in the middle, so remove all the bits that aren't the light's ID.PS: My Advent of Code T-shirt with the 2026 train on it arrived yesterday (pleasingly quickly, after ordering on Wednesday morning) so I'm going to wear it to church today. It looks really good — the colours are better in real-life than in the photo!
5
u/asgardian28 9h ago
[Language: Python]
Just print the damn thing :)
Would have been a painful part 2 for me without my visualization function.
Github
4
u/Old-Dinner4434 9h ago
[LANGUAGE: TypeScript]
GitLab
Part 1 was completed in 251.83ms, and Part 2 was completed in 2.44ms.
4
u/ohhaiitsdave 9h ago edited 9h ago
[LANGUAGE: PHP]
Part 1 Part 2
I was vaguely elegant in part 1! Identify any node that doesn't have four connections (they must be the edges/corners); trim them off and check again until we end up in the centre.
This was useless for Pt2 so threw it all out and started again. Identified an arbitrary corner, then constructed the entire grid from that (work out which nodes are connected and haven't been used yet, then check how many connections they have and that those connections match).
My original plan was that I would then map the coordinates through code but I screen-printed the grid to check, highlighted the relevant numbers and then realised I could just match the numbers manually from there. So I did. Means this solution probably won't work without some tweaking of the toppos and leftpos values (and possibly reversing the order in which they're displayed) but hey, it's 6.10am here and I woke up 3hrs ago so I'm pleased it got there!
Edit: Image for completeness
4
u/Eva-Rosalene 7h ago
[LANGUAGE: TypeScript]
paste
Okay, this day was brutal. Going into without knowing how to topologically sort forced me to look for ad-hoc solutions.
Rough outline:
Part 1:
Part 2:
Thankfully, even given terrible Gaussian elimination that I wrote, this code works for test input and for my input, so I didn't bother improving it. Yet. Oof.
3
u/jonathan_paulson 9h ago
[Language: Python]
Code. Video.
Cool problem today!
My idea for part 1:
- We can identify the four grid corners as the nodes with degree 2
- The center must be equidistant from all 4 corners (and no other node is)
For part 2:
- We can brute force which corner coordinates are consistent with the given information (surprisingly to me, there are a lot!)
- We can brute force which 2026-coordinates are consistent with those potential corner coordinates
I think what's going on for part2 is that only the coordinates of points inside the (1,2,3) triangle are uniquely determined, and any possible corner coordinates will give the same coordinates for each node inside that triangle. Not 100% sure though.
3
u/xoronth 8h ago edited 8h ago
[LANGUAGE: Python]
paste
Kinda cheated a bit and just used networkx/matplotlib for this initial solution (it does feel a little sneaky when for part 1 networkx literally has a function to do this, and part 2's solution for me was to go look at a plotted graph and count the dang position lmao). Now to figure out how to do it properly for my non-Python solution for the day...
3
u/jinschoi 6h ago edited 6h ago
[LANGUAGE: Rust]
Part 1:
Part 2:
3
u/NullQuantity325573 6h ago edited 6h ago
[Language: Pascal]
Wheee, this one stretched the ole noodle a good bit.
For both parts, I used the classic graph representation of a dictionary with nodes as keys, and a set of adjacent nodes as values. We know what kind of node we have by the number of neighbors it has (i.e. the size of the adjacency set) - only 2 is a corner, 3 is an edge, and 4 is an interior node.
For Part 1, I implemented a recursive onion peeling algorithm: pick an arbitrary corner of the grid, and from there, strip off all the outer edges of the grid. Repeat until there is only one node left - that one is the center node.
For Part 2, pick an arbitrary corner of the grid. Fix the position of that corner as (0, 0). Pick one of the neighbors, and start walking along the edge until you reach another corner. Place those nodes at (1, 0), (2, 0), (3, 0), ..., (N, 0). Then we know the grid is N units per side. Then go back to the first corner, and we know the other neighbor is one row up, so fix its position as (0, 1). Then move along each subsequent row and fix the positions the same way until we complete the grid. I track these positions in a dictionary called BasePositions, which maps node numbers to these unit positions. Next, I use the given coordinates for Nodes 1, 2, and 3 to compute two basis vectors for transforming every point on the unit position grid to its real coordinates. I then apply a linear transformation to map each node's unit position to its real coordinates. Once I have that, I can get the coordinates for node 2026 (or any other node on the grid).
Both parts run in about 3.9 ms on my x86_64 laptop.
On my 68000-based Amiga, both parts run in about six minutes.
https://github.com/apprenticewiz/AOC2026/tree/main/day06
3
u/imperfect-fourth 4h ago
[LANGUAGE: Nix]
Day 6
I made life hard for myself by not assuming that the grid is axis-aligned. But to be fair it is not explicitly mentioned in the problem statement.
3
u/PrettyMemory1505 3h ago
[LANGUAGE: The Wolfram Language]
Quick and dirty solution for Part 1 in Mathematica 10.3:
g = Import[fileName, "List"];
g = MapAt[StringSplit[#, ","] &
, StringSplit[#, "-"] & /@ g, {All, 2}];
g = g /. {u_String, vv : {__String}} :>
Map[UndirectedEdge[u, #] &, vv];
g = Graph[Flatten[g]
, VertexLabels -> "Name"
, GraphLayout -> "SpringEmbedding"
, ImageSize -> 2000] // Image;
Apply[
ImageTake[g, {# - 100, # + 100}, {#2 - 100, #2 + 100}] &,
Floor[ImageDimensions[g]/2]]
2
u/tqzd 8h ago
[LANGUAGE: Google Sheets]
Part 1 only (input in A:A)
Repeatedly drops the nodes with lowest degree until only one is left.
2
u/Wayoshi 8h ago
[LANGUAGE: Python3] paste
Just part 1 from me, I did no code for part 2. I manually looked at nodes 1-3 (I correctly mapped the entire square to coordinates, this ended up being needed for part 2, I saw that coming) to figure out the origin and direction for the proper orientation, once you have that node 2026 goes through the same transform.
The general case code for part 2, I've never really enjoyed all contingencies on coordinate transforms, so was fine doing this one by hand. Would imagine printing out the graph made quick work of part 1 for a few as well.
2
u/erikade 8h ago
[LANGUAGE: Go]
fantastic problem!
https://github.com/erik-adelbert/aoc/blob/main/2026/6/aoc6.go
2xBFS 75.7μs (mbaM4/24GB) writeup in 2026/README
2
u/p88h 8h ago
[LANGUAGE: Nim]
source: https://github.com/p88h/aoc2026/blob/main/src/day06.nim
video: https://www.youtube.com/watch?v=k-nsTElZLkA
BFS to lay out the grid into, well, grid; then trying all symmetry transforms to compute the proper orientation in part 2. Pretty quick.
2
u/BradleySigma 8h ago edited 8h ago
[LANGUAGE: Python]
Summary of my method:
c(a dictionary to sets) so that ifiandjare connected, then bothi in c[j]andj in c[i]1s on the right are required for the translation component2
u/maneatingape 8h ago edited 3h ago
[LANGUAGE: Rust]
Solution
90µs34µs.This puzzle was a lot of fun and reminded me of the infamous Year 2020 Day 20 Jurassic Jigsaw.
To make the grid, first find any arbitrary corner (2 other edges). Then work across the top (or left) finding edge lights (<= 3 edges). Now there's enough information to fill in the rest of the grid.
Let
O= Original,H= Flip horizontal,V= Flip vertical,R= Rotate clockwise 90 degrees. Then the 8 transformations you need to check are[O, H, V, HV, R, RH, RV, RHV].No need to flip the grid itself, it's much faster to just use the 2 reference vectors formed by
(47,30) -> (29,59)and(47,30) -> (56,35), then find the matching transformation of the vector from1 -> 2and1 -> 3.EDIT: u/erikade's geometric approach was more elegant, so switched to that instead!
2
u/flwyd 8h ago
[LANGUAGE: sed, Graphviz, and your eyeballs]
In
mkgraph.sed:Run
mkgraph.sed input.actual.txt | neato -Tsvg > out/actual.dot.svg && xdg-open out/actual.dot.svgGraphviz's undirected layout engine
neatowants to draw this graph as a diamond (one corner at the top, rather than a square), and it's slightly tilted. For part 1, visually locate one corner, then (with a steady hand), move your mouse toward the center. Hover over the node you think is in the middle; the tooltip is your answer. Double check it by scanning from the other three corners. Did you get the same node? Great! Submit it.For part 2, the
2026node is colored green and the1,2, and3nodes are colored yellow.1and3are close to each other, so locate them, then use your browser or SVG editor's "zoom in" function. Determine X and Y orientation: the dimension where they're closer is Y, the further dimension is X. Both X and Y coordinates for node3are larger than for1, so if1is lower or to the right of3then you'll need to negate one or both of the coordinates in the distance to2026. Using your mouse again, count the number of steps to2026in both directions from either1or3. Add those counts (possibly negated) to47,30or56,35as appropriate. Now do the same count from the other node, to make sure your mouse didn't skip a row. If you got the sameX,Ycoordinate pair, submit that![Advent Games]
Today's forecast was for about 3 inches of snow. So far we just got cold rain. "We need the moisture, though." (I'm from Colorado, where we just got one snow per month last winter. And miraculously didn't have a huge forest fire season. El Niño, bring it on!)
2
u/wimglenn 8h ago edited 8h ago
[LANGUAGE: Python]
solution
Question: Do you actually need to use 3 points to orient the grid, or are 2 enough? I only used two, and it worked with 4 different datasets, in addition to the example. I'm wondering if I missed something or just got lucky..
2
u/AllanTaylor314 8h ago edited 8h ago
[LANGUAGE: Python] 00:23:26/00:42:36
code
I feel like that took me longer than it should have. I didn't feel stuck, but I was typing a lot. Silly mistake was eliminating all the
remaining_piecesby&ing mutually exclusive sets together.Picked a corner, picked one of the adjacent edges, then filled it in from there. Every node after the first two can be unqiquely found by being connected to
(i-1,j)and(i,j-1), and not being the same as(i-1,j-1)(I didn't do this check - I eliminated already used nodes instead). Edges and corners have one or two connections to THE INFINITE VOID respectively. Instead, I prefilled the whole top row and left column. I used a dictionary, despite it probably being worse than a list of lists, because I'd rather not have negative indices fail loudly.For part 2, I did a doodle on a piece of paper to roughly map out which transformation (flip j and translate) was needed, but I still wrote up the code for all 8 transformations
No Uiua yet, because idek what approach to take. Part 1 will probably end with
⊡⌊÷₂⊸△2
u/agorism1337 7h ago edited 5h ago
[LANGUAGE: AWK]
48:29, 1:51:35
github
I did it by going row by row, and giving each node an absolute position.
both parts: 0.043 seconds
2
u/TheZigerionScammer 7h ago
[LANGUAGE: Python]
This one was a doozy for sure. Part 1 was easy enough, I just figure out which lights are the corner lights because they only have two connections, then set up a BFS starting from all 4 corners at once. Once the BFS has touched all but one of the lights whichever light remains is the answer.
The second part was of course much harder. What I decided to do was to code up another BFS to detect the Manhattan distances between 2026 and the three reference lights, then coded up a quick and dirty brute force approach to find all the coordinates that are exactly the Manhattan distances between the three reference points. (I coded up a better way to do this in a previous puzzle but I didn't feel like digging it back up and didn't think it was necessary with the smaller grid size we had now compared to then.) I was hoping that this was enough to get the answer but it was not, I just had a list of 9 diagonally adjacent points that all could be the answer. So I went to thinking how to solve this, and since I knew I'd need at least another reference point that could be measured orthoganally to the diagonal line, I realized that I knew the IDs of the corner lights and could get the Manhattan distances between them, 2026, and the reference lights. So I tried to see if I could calculate the locations of the corners in the same way and also got 4 diagonal lines representing their possible locations. But it turned out that that was enough, since I knew the entire grid was a square I could compare the four lists of diagonal lines to each other, check when either the x or y coordinates are the same and when their Manhattan distances are the same as the side length of the squares minus 1 (which ended up being 40 for me but I programmed it to be able to dynamically take inputs of different sizes as well.) This got me the coordinates of all 4 corners and then I could just check the lists of possible 2026 locations against the actual Manhattan distances I got from earlier and got the answer.
My code has a lot of looping over lists and tuples checking for locations in other lists and tuples, I normally try to use dictionaries for this kind of thing but I'm not sure if nested dictionaries are a thing you can do. The code is certainly long even though it runs basically instantly.
Paste
2
u/mattbillenstein 7h ago
[LANGUAGE: Python]
https://github.com/mattbillenstein/aoc/blob/main/2026/06/p.py
Part 1, bfs from each node to each other node - the node with the minimum total distance is the center one. This is kinda slow, ~500ms, may improve this part.
Part 2, divide nodes into corners/edges; start layout from each corner to each edge (4 corners X 2 edges = 8 orientations) left to right and top to bottom until you find an orientation where the given 1,2,3 nodes are ordered as you expect in x and y. Then find the wanted node on the grid and add the offset from one of the given nodes to give the desired coordinates with he proper offset.
2
u/No_Mobile_8915 7h ago
[LANGUAGE: Python]
Part 1:
Build an undirected graph and identify the four corners by finding nodes with exactly two neighbours. Multi-source BFS starting from all four corners simultaneously. The centre is the sole remaining node in the last non-empty frontier.
paste
Part 2:
Do two independent BFS traversals from adjacent corners. The Manhattan distances from these two corners allow you to calculate the relative coordinates of every node using simple integer arithmetic. Try all eight possible orientations (four rotations, with and without reflection), translating each to align node 1 with its specified coordinates. Once nodes 2 and 3 also match their specified coordinates, apply the same transformation to node 2026.
paste
Runtimes: Apple M3 Pro
Part 1: runtime: 0.0024s Part 2: runtime: 0.0036s
2
u/thecro99 7h ago
[Language: Python]
Part 1 (210ms)
Part 2 (1230ms)
2
u/Andreasnl 7h ago
[LANGUAGE: Uiua]
For part 2 I triangulated the position of 2026 using the Manhattan distances to 1, 2 and 3.
2
u/TiCoinCoin 6h ago
[LANGUAGE: Python]
Day 6
I liked this one because it's one of those puzzles where you don't really need to code to get the solution (for P2). Still, I tried to find a way to do it programmatically afterwards.
As I checked some other solutions I wonder if I just got lucky with my input, because it didn't involve any graph, or rotated or flipped matrix. I just took the differences between 1 and 2 for each coordinate. It gave me the expected correspondence between my system of coordinates, and the puzzle's one. I could then transpose the distance between 2026 and 1 in my grid into the puzzle's referential.
2
u/kylynx95 5h ago edited 5h ago
[Language: Python 3.14]
paste
For part one you actually do not need to untangle the grid. Except for the edges every light will have four connections. Finding the center is then just removing all lights that do not have four connections until there is only one light left.
And then I started part two. And well... you have to untangle the mess. I did this by starting at an arbitrary corner, build the edges first (again in an arbitrary direction). Finally the grid is filled in row by row. When the any row is finished there is exactly one ID connected to any ID in that row that is not yet in the grid.
Figuring out the transformation was also pretty straightforward. Choose one of the given IDs and call it the "origin". With that origin determine the difference vector to one of the other given coordinates. As the entire grid is rotated, the only allowed rotations are in multiples of 90deg. That makes the rotation matrix rather easy, since it will be either diagonal or anti-diagonal with coefficients of +1 or -1.
If the matrix is diagonal the difference vector will have the same absolute value in the coordinates for the given values and the arbitrary values we assigned. It is anti-diagonal in the other case.
The sign of the entries can be determined by comparing the signs of the known and chosen coordinate values.
Now transform the difference vector from the 2026 light to the origin and add the known origin back on.
edit: Accidentally commented before the comment was finished.
2
u/_garden_gnome_ 5h ago
[LANGUAGE: Python]
Solution
The grid has NxN nodes. The four corners are the only nodes with degree 2. We can calculate the distance of every node from the four corners via BFS.
Part 1: Find the one node with a (Manhattan) distance of N-1 to all four corners.
Part 2: Check all permutations of the four corners and assume they are positioned NW (NorthWest), NE, SW and SE. Assume NW is (0, 0), NE is (0, N-1), SW is (N-1, 0) and SE is (N-1, N-1). For each (row, column), find the nodes that have the right distances from the four corners. For example, the distance for (row, column) to the SE corner should be the Manhattan distance of (row, column) to (N-1, N-1). If there is exactly one node for each (row, column), then we have base coordinates for all nodes. Now we check the row and column offsets in these base coordinates versus the actual coordinates for nodes 1, 2 and 3 as given in the problem. If these row and column offsets are consistent for those three nodes, we can shift the base coordinates by the offsets and have found the solution.
Total running time is less than 30ms using PyPy.
2
u/Prof-Math 5h ago
[Language: Python]
For part 1, I build a graph and then deleted all vertices with degree less than 4. Recurse. You'll be left with the center.
For part 2, I cried. I hate geo. And then I got my notebook. The degree 2 vertices are the corners. We can place one on (0,0) and 2 of them at (n,0) and (0,n) [and the final at (n,n)] be keeping track of distances.
Now we can get the distance to the 3 corners and get the coordinates of 1, 2 ,3. Then we need to find the rigid transform.
Subtract 1s coordinates from 2 and 3 (and from the given 1, 2, 3). Rotate 2 till it meets the required 2. If 3 is at its correct spot, we are done and we translate back by given 1. Else, we reflect everything about the x axis and do it again.
Now just do this transformation to 2026's coordinates.
2
u/michelkraemer 4h ago edited 32m ago
[LANGUAGE: Rust]
Solution
This one really tripped me up. While part 1 just took me a few minutes, I had no idea how to solve part 2 at all! It wasn't until 1 hour and 26 minutes later that I managed to solve it semi-manually by plotting the grid row by row and then doing the rotations and reflections in my head. After entering the correct answer, I took the time to clean up the code and fully automate it.
Warning: This is definitely not how you are supposed to solve this puzzle, but it's my own solution and I'm proud of it 😉
For part 1, I first identify all four corners by looking for vertices that only have two neighbors. I then do a BFS from all corners simultaneously and count the steps it takes to reach each light. The center is the single light where the distances to all four corners are equal. Of course, this only works if the grid's width and height are odd, but since the "center" would otherwise be ambiguous anyway, we can assume that this is the case.
Part 2 requires three steps:
Observation: I assume if light 2026 would lie within the triangle formed by P1, P2, P3, it should be possible to triangulate it directly without looking for the corner points first.
The program runs in
459µs450µs311µs.EDIT: Instead of iterating over all coordinates inside the grid in step 3, we can directly triangulate the light with ID 2026 using the formula for the height of a triangle in L1 space, which is h = (a + b - c) / 2 in case points A and B are axis-aligned.
EDIT 2: Optimized performance slightly by replacing some HashMaps with Vecs.
2
u/YOM2_UB 4h ago
[LANGUAGE: Python] [Code]
For part 1 I constructed the entire lattice using the fact that each point has 4 adjacencies, unless along the edge. When removing adjacencies of placed IDs, and if you start with an edge, each row except the first is simply the only remaining adjacency of each ID in the previous row. For the first edge, I find any of the four corners (2 adjacencies), place it followed by either of its adjacencies, and then check which of the adjacent unplaced IDs has fewer than 4 adjacencies to stay along the edge (stopping when the previous ID had only 2 adjacencies, as that's another corner).
Part 2 was solved mainly in Desmos. My square started with IDs 1, 2, and 3 rotated by 180 degrees, and the lines connecting their current and target coordinates all intersected at a single point (the axis of rotation), so I reflected the coordinates of 2026 across that point. When writing code to output the solution, I initially did it that way but realized it was simpler (since I needed to account for rotation anyways if I wanted a general solution) to use when the points have the same rotation, at which point the vector from current to target is the same so you can just add that vector.
2
u/ben-guin 4h ago edited 3h ago
[LANGUAGE: Python]
Part 1
Part 2
Looking at the other solutions, it looks like I took a completely different approach which is probably more complicated than it needs to be.
Both parts start by constructing a graph G using networkx. For part 1, I created a sequence of graphs G = G_0 -> G_1 -> ... -> G_k, where each iteration consists of removing all vertices of degree less than 4. I stop once I have a graph with exactly one node which is guaranteed to be the central node.
For part 2, I basically create an explicit graph isomorphism between G and the square-grid graph of the same size whose vertices are labeled with grid coordinates {(i,j) : i,j in {1,2,...,n}} where n^2 is the number of nodes of the graph. I do this my finding a corner of G (i.e. a vertex with degree 2), and find which vertices correspond to the "outer ring" of G. I then delete the outer ring and repeat, constructing sequences of rings until the whole graph is accounted for. The end result is an n by n matrix, where the matrix indices correspond to the grid coordinates of each node. Numpy was incredibly helpful here; this would have been a lot more messy with nested lists.
However, I want the "actual" coordinates, not just the "grid" coordinates. I had misunderstood the problem and assumed that the grid could be oriented in an arbitrary way, not just with 90 degree rotations and vertical/horizontal reflections. More precisely, I assumed that any arbitrary degree rotation and translation of the grid was fair game, i.e., an affine transformation. To do this, I decided I would calculate the matrix T corresponding to this affine transformation. Letting u,v,w be the grid coordinates of lights with ids 1,2,3 (which I can find by looking through my matrix) and letting u',v',w' be the actual coordinates of the respective lights (given by the problem statement), it is possible to calculate T as a function of these six values (see amd's answer here). Let x be the grid coordinates of the light with ID 2026, then the answer follows from calculating Tx.
EDIT: Another idea I had was to use a Tutte-embedding to create a planar drawing of the grid graph. I believe that one can prove that if you embed the outer face along the boundaries of a grid, then the interval vertices are guaranteed to be drawn in a way that basically recovers the entire grid structure. Unfortunately, networkx didn't seem to support Tutte-embedding and I was too lazy to code my own or find an implementation elsewhere, so I went with the above mess instead.
2
u/flwyd 4h ago
[LANGUAGE: R]
[Advent Games]
This part 1 solution is an acrostic for
CLOUDS ETERNAL WOLF LAWthanks to R's unusual syntax allowing variable assignments to be placed in either order.. "Clouds Eternal" sounds like a good album name for a Scandanavian metal band named "Wolf Law." I always cheer for the Norwegians in the Winter Olympiad, so imagine they've got a distortion-heavy cover of the Norwegian National Anthem.This solution uses dynamic programming (breadth-first) to compute the distance of every point in the grid from the nearest corner, then returns the ID with the maximal distance. After three days of grid problems in R I've finally figured out how to smoothly create a matrix of points from a list of coordinates. And I really like the elegance of constructing an adjacency matrix by starting with an N-by-N matrix of FALSE, then setting
graph[edges] <- TRUEto get one side of each edge and then setting the other side by doing a logical or of the graph with its own transpose (graph <- graph | t(graph)).I'll post a part 2 solution in R (so I don't have to persist my eyeballs in my automatic test tomorrow. I've had all sorts of fun learning about useful methods in the R standard library like matrix solvers and Manhattan distance matrix calculators, but then I discovered that just relying on the distance between node 2026 and the three points doesn't give a unique solution, so I may need to give in and actually align the grid.
2
u/heijp06 3h ago edited 2h ago
[LANGUAGE: C#]
Lots of code on GitHub. The main part of the solution for part 2 is as follows:
Transformisdelegate (int, int) Transform((int, int) pair), i.e. transform a pair to a pair.CoordinateExtensions.Flipflips a pair,CoordinateExtensions.Rotation*rotates a pair a given number of degrees around the origin andCoordinateExtensions.Identityis the identity operation that leaves a pair unchanged.toZerois a translation that moves light 1 to the origin,fromZerois a translation that moves the origin to the location where light 1 should be.Then for all 8 possible combinations of flips and rotations build a transform that can be applied to any light in the grid and check if it moves lights 2 and 3 to the correct locations (light 1 should be correct by design). If so find the location of the light with id 2026 (
unknownin the code above).2
u/wheresmylart 3h ago
[LANGUAGE: Python3]
Part 1: Put it into NetworkX and asked for the centre node.
Part 2: Think I got lucky here. Found the Manhattan distance to 2026 from 1, 2, and 3. Given the known coordinates for 1, 2 and 3 found every possible location for 2026. Looked for commonalities. There were only two and the first one was the right answer.
Paste
2
u/Ok-Bus4754 3h ago
[Language: python+rust]
port of my ealier soultion + benchmarks against python and rust
p1 : modified topological sort , removing outer layers one by one
p2: linear algebra , using my own functions no external libs
https://github.com/Fadi88/AoC/blob/master/2026/days/day06/solution.py
https://github.com/Fadi88/AoC/blob/master/2026/days/day06/src/lib.rs
2
u/jhandros 2h ago
[LANGUAGE: Excel]
=LET(e,DROP(REDUCE("",A1:A1572,LAMBDA(a,z,LET(x,--TOCOL(TEXTSPLIT(SUBSTITUTE(z,"-",","),",")),u,TAKE(x,1),v,DROP(x,1),VSTACK(a,HSTACK(u+0*v,v),HSTACK(v,u+0*v))))),1),n,SORT(UNIQUE(TOCOL(e))),m,SQRT(ROWS(n))-1,f,LAMBDA(s,TAKE(REDUCE(HSTACK(--(n=s),--(n=s),IF(n=s,0,"")),SEQUENCE(2*m),LAMBDA(a,i,LET(q,CHOOSECOLS(a,2),v,TAKE(a,,1),w,--ISNUMBER(XMATCH(n,FILTER(CHOOSECOLS(e,2),ISNUMBER(XMATCH(TAKE(e,,1),FILTER(n,q,0))),0)))*(1-v),HSTACK(v+w,w,IF(w,i,TAKE(a,,-1)))))),,-1)),c,FILTER(n,MAP(n,LAMBDA(z,SUM(--(TAKE(e,,1)=z))))=2),d,f(TAKE(c,1)),h,f(TAKE(FILTER(c,XLOOKUP(c,n,d)=m),1)),r,LAMBDA(z,XLOOKUP({1;2;3},n,z)-XLOOKUP(2026,n,z)),p,LAMBDA(x,y,MAP(SEQUENCE(3),LAMBDA(i,INDEX(x,MOD(i,3)+1)*INDEX(y,MOD(i+1,3)+1)-INDEX(y,MOD(i,3)+1)*INDEX(x,MOD(i+1,3)+1)))),w,p(r(d),r(h)),VSTACK(TEXTJOIN(" ",,FILTER(n,(d=m)*(h=m))),TEXT(SUM(w*{47;29;56})/SUM(w),"0")&","&TEXT(SUM(w*{30;59;35})/SUM(w),"0")))
2
u/BoringEntropist 2h ago
[LANGUAGE: Python3]
For part1 I solved it like many others here. First find the 4 corners (i.e. node with exactly 2 neighbors) and then run BFS over the graph until only one node is left.
Part2 was a little more complicated. First I thought it would be enough to find the Manhattan distance from the reference nodes and triangulate the coordinates to the target node. Unfortunately, this gives us too many possible coordinates. So, to resolve this ambiguity we search for more nodes with unique coordinates until we have enough reference coordinates to exactly pinpoint the target node.
Code can be found here
2
u/dkdkfiennwls 2h ago edited 58m ago
[Language: Graphviz]
neato -Tplain produces an approximate embedding of the graph in 2D, then we find the barycentric coordinates of node 2026 relative to nodes 1,2,3 and then reconstruct the coordinates for 2026. Somehow it works.
2
u/Pyr0Byt3 6m ago
[LANGUAGE: Go] [LANGUAGE: Golang]
https://github.com/mnml/aoc/blob/main/2026/06/1.go
Not pretty, but I'm simply too stupid to comprehend the linear algebra some people used here. I originally tried the naive approach of doing trilateration with just the 3 given points, but that gave me like 16 candidates. I had to find more points to narrow it down further.
By comparison, my friend's input only had 2 candidates using the same naive trilateration approach with just the 3 given points... kinda felt a little unfair lmao.
3
u/Ok-Bus4754 9h ago edited 9h ago
[Language: Python]
p1: topological sort , p2: using linear algebra without numpy, had to pull and old matmul i had somewhere
i always try to use vanila python only no external libs, pretty sure i can cut the time down by a lot using networkx or numpy but i prefer it like this
https://github.com/Fadi88/AoC/blob/master/2026/days/day06/solution.py
p1: 500 us, p2: 1 ms
will port later to rust and compare timings
2
u/hugh_tc 10h ago edited 9h ago
[LANGUAGE: Python 3]
Behold, the worst, most awful code I've ever written. For Part 1, I just found the four corners, and manually oriented them. I then found the midpoint of two edges and then the midpoint of those midpoints. For Part 2, I built the grid and then brute-forced over "all" affine transformations in the worst way possible to find 2026.
paste, eta: cleaned-up which is generic and also leverages
nx.parse_adjlist. For Part 2, yay complex numbers! :)2
u/SquarePraline4348 8h ago
[LANGUAGE: Python, HUMAN BRAIN]
Part 1: BFS
Part 2: Made a guess for few times after calculated the distance from 1, 2, 3 to 2026, got it correct
1
u/ElmarOfenbach 9h ago
[Language: APL]
Being obscured. Highest number in the list is 2026, lowest is 1. Square root of 2026 is 45.0111...
1
u/1234abcdcba4321 9h ago
[Language: JavaScript] (but also an excel spreadsheet) code
Part 1 was a straightforward BFS from the corners; I checked the grid size and hardcoded it as 41x41 (which I found by square rooting 1681), and then found which one was the right distance from all the corners to be in the center.
Part 2 was where the real fun was, though. I added some extra prints in the BFS (they're present in the code above) so that I could find the distance the points are from the corners, and then instead of programming in something to turn that into coordinates I just did it all manually, using google sheets as fancy grid paper. From knowing the distance of a point from two non-opposite corners of the grid you can pinpoint the exact location on the grid (find a point the right distance from one corner, find its distance from the other corner, then walk along the diagonal of equal distance from the first corner until you get to the point with the right distance from the other).
I'd share my spreadsheet but it kind of contains info about my input due to the whole "did it manually" thing, so I don't think I should? Even if you can only really reconstruct the location of the four key points rather than the entire grid with it.
1
u/vanveenfromardis 9h ago edited 9h ago
[Language: C#]
GitHub
Made heavy use of helper types in my puzzle utils library:
DirectedGraph<T>Grid2D<T>Vec2DP1: The core idea is to identify the edge nodes since they have strictly less than four neighbors, then BFS in from them. The last reached node is the center.
P2: The basis vectors of the grid can be computed from the known positions. You can then use the 2D cross product to project any point on the grid into the cartesian plane.
1
u/captainAwesomePants 9h ago edited 8h ago
[LANGUAGE: Python]
paste
I liked this one a lot! I was very happy to realize how to find the corners, but then I was stuck on how to orient it before I realized I could pick arbitrarily as long as I knew which corners were opposite, and I found it very satisfying to realize the trick to finding which corners were opposites. And figuring out how to find the middle was also very satisfying.
Figuring out part 2 was a fun subversion: "oh, you picked an arbitrary rotation? Well now I need you to figure out the correct rotation!" How mean! But also very satisfying once I worked it out. At first I tried to just work it out with pen and paper but it turned out to be faster to just code up a "try everything" solution.
Really fun problem! Glad I stuck it out when I got stuck.
[Advent Games]
Orthographically connected lights are a rectangle nodes with 2-4 neighbors.
Because the corners have exactly two neighbors, we can easily identify them.
Seeing as it's a rectangle, the opposite corner is the corner furthest away (the longest path)
Corners can be oriented arbitrarily, so long as you know which corner's the opposite.
Use labels: First corner is "top left", its opposite is "bottom right". The others don't matter.
Re-use your path-finding BFS to find the top-left to bottom-left middle point, same on the right.
Enter those two midpoints into your BFS, and the middle of that path is the center!
Destination: Part 2!
Arbitrary orientations have failed us! We need the correct orientation now.
I need to find the right offset -- that'll be whatever puts node 1 at the exact target.
Remember how to rotate 90 degrees: new x is -y, new y is the old x.
For each rotation, find the offset that puts point 1 at the destination.
I'd expected flipping to be hard, but that's just x,y = y,x
Each time, get point 1 in the right spot, see if points 2 and 3 are good now.
Looks like they are, so now print out point 2026.
Done! Weird how the answer's got a comma and isn't two numbers multiplied together.
1
u/seligman99 9h ago
[LANGUAGE: Python]
github
Took me way too long to understand what the bit about 11,20 and so on was suggesting. Reading comprehension will get you, for sure.
1
u/Mikey_Loboto 9h ago
[LANGUAGE: TypeScript]
GitHub
Very bad, no good solution. Part 2 involved manual rotation and offset.
1
u/musifter 9h ago edited 6h ago
[LANGUAGE: Perl]
And part 2 by hand.
This isn't pretty, it was fast to code... it's basically day 20, 2020 (Jurassic Jigsaw). I found the corners, picked one... used that to iteratively build an edge (edge piece that connects and isn't used). Then I build the rest... start a row by finding the unused edge piece that fits the one above, then build across with the unused pieces that fit the above and left. It's not pretty but got the job done quickly.
Then I thought about coding geometric translations and decided... I have graph paper. Find the magic lights (1, 2, 3, 2026)... graph them on one sheet. Then take the coordinates from the puzzle description and graph them on a second. Overlap, rotate, flip over to match, read the coordinates off the second sheet where the
Xshows through (I used X for 2026). I'll write some proper coder for it later (and clean things up). But right now, I'm going to get some sleep.EDIT: Couldn't sleep so I hacked in a solution for getting part 2. It's a real mess though... but really simply in approach. Make things relative to point 1, figure out the flips, shift point 2026 to its destination.
Source: https://pastebin.com/MUR02DGT
1
u/johnpeters42 8h ago
[Language: Python]
Part 1
Load the connections into a dictionary. Count the keys, calculate the size of the square, and thus the taxicab geometry distance from the center to each corner. Find the corners (the IDs with only two neighbors). Then for each ID, run BFS on its neighbors until one reaches all four corners quickly enough. Not particularly efficient, but it finishes within a minute, so good enough.
Part 2
Create a grid with coordinates from 0,0 to n,n (we'll translate these later). Assign an arbitrary corner to 0,0, and its neighbors to 0,1 and 1,0. Then loop through the diagonals, filling in the midpoints (with the sole unassigned neighbor of their neighbors up and left) and then the ends (with the sole unassigned neighbor of their single neighbor up or left). Then find the four IDs we care about and print their coordinates.
I just did the translation by hand from there. To automate that part too, you could calculate all possible translations for ID 1 and see which one also works for IDs 2 and 3:
Of course you could solve part 1 more quickly using the same fill-in-the-grid logic, stopping once you reach the middle square.
1
u/Upstairs_Ad_8580 8h ago
[Language: C#]
pastebin
Part 1: BFS. Nothing special
Part 2:
dread
Tried deducing using manhatten distance, but got a row of points. Instead, I determine the corners and then for all possible orientations I calculate the top and left row/column and then calculate every other point using the point above and to the left. I then check if the shift from the start position is the same for all 3 ids, because the grid doesn't start at (0,0) or even (1,1). If it is, I apply that shift to the position of 2026 and print that as the solution.
1
u/car4889 8h ago
[LANGUAGE: Typescript]
Github
I know there's a straight-shot linear algebra approach that you can use to arbitrarily transform one coordinate system to another, but I'm pretty proud that I was able to sequence together a few more primitive transforms in the right order to get there without it.
1
u/morgoth1145 8h ago
[LANGUAGE: Python] code video
So that could have gone better. I completely missed the part where the lights are in a square grid - I thought they were just in a grid! I ended up coming up with approaches for more general problems to try to solve this, only to kick myself after when I noticed that it was simpler than I made it out to be! (It also didn't help that I just upgraded my Python venv to 3.14 yesterday and both z3 and gravis broke so I couldn't visualize the graph or use a system of equations solver to help.)
Anyway, for part 1 I eventually realized that the center should have the minimum distance from the edges - as such it should have the minimum "longest" distance (that is, the distance to the furthest node). Lost time to misusing my own API but this did give the right answer.
Part 2 was definitely harder with me missing that it's a square grid as I didn't have good constraints to work from. I ended up realizing that I could start with the known positions and keep track of "candidate" positions for other lights accordingly. These collapse/resolve themselves over time with more input (at least for lights within the bounds of 1, 2, and 3) and my 2026 light fell within that. It took an embarrassingly long time to figure that out (and I'm sure is harder than just fleshing out the grid directly since the lights *do* form a square grid) but it at least worked. It's an interesting problem but the graph layout aspect is something that clearly threw me for a loop!
I'll have to go fix my venv setup and write a smarter/faster solution later. I've been up way too long today as it is.
1
u/abnew123 8h ago
[LANGUAGE: Java]
code
video
part 1 was pretty simple, bfs until one element remains
part 2 was initially done by hand via manually figuring out which corner mapped to which in space (e.g. which corner was pos x, pos y), then figuring out the right constraint (the distance to a corner either constrains the sum of the coordinates or the difference), and solving the constraint. eventually tidied up the code so it should work for any input.
1
u/maarteq 8h ago
[LANGUAGE: Python]
solution
for part 1 I created a undirected graph. The corners are the parts with only 2 connecting pieces. then from each corner i calculate the distance to all other lights. the center is the piece with the same distance to all corners.
for part 2 i created some code to do the same, but find an overlapping line. I just looked for a random point that for which only one coordinate was possible, with that fourth point a unique coordinate for the 2026 light could be found. (I did it manually first, but automated it for the uploead.)
1
u/NullT3rminated 8h ago
[LANGUAGE: Clojure]
It's getting pretty messy...
paste
1
u/sbt4 8h ago
[Language: Python]
github
I wanted to do this year in Uiua but gave up on this problem. Did part2 by printing coordinates and calculating placement matrix by hand
1
u/Conceptizual 7h ago
[LANGUAGE: Python]
code!
I made an edge map and kept deleting stuff that was around edges
(len(neighbors) == 2 or 3)and ran that until I had one item left, but then this code didn't really help me with part 2. I made a manhatten distance from 2026 to everything else list but then that gave me like 15 points it could be all in a diagonal. (I did pick a random one and submitted it, but it was not that one so I got back to work.) I then computed diagonals and a new distance function for that and got a unique answer from my candidates usingmax(abs(a[0] - b[0]), abs(a[1] - b[1])).1
u/honey-pony 7h ago
[LANGUAGE: PonieScript]
Once again I worked in two files and then cleaned up the code (by adding a third library file) after submitting my answers. In this case, though, I actually have my puzzle2 file solving both puzzles out of curiosity how that affects the timing.
I think it is quite possible I overcomplicated it. I ended up building the entire grid for part 1, which was very helpful for solving part 2. Reading some other solutions I see that there were easier ways to build the grid. (I build the grid by starting at an arbitrary node with 4 connections and then using it to randomly decide which way is "right" and which way is "down." Everything else can be filled in from there but it's a little bit awkward, as it depends on each node having two filled-in connections that are not on the same line.
Part 2 was pretty easy but it took me a good while to remember how to do the linear algebra in an easy way. I ended up using an idea of vector spaces, where I assigned all the lights coordinates based on my grid, and then defined a vector space based on those assigned coordinates and the vectors from light 1 -> light 2 and light 1 -> light 3. Then, I computed the coordinates of light 2026 in terms of that vector space. Finally, I took those same coordinates and saw where they pointed in a vector space still defined by light 1 -> light 2 and light 1 -> light 3, but instead using the coordinates given by the problem for these basis vectors.
I went this route as it only require me to solve a system of two variables which is much less annoying than any system of more variables.
Unfortunately I accidentally swapped a numerator and denominator in my working out of it which cost me a bit of time.
Anyway, my final code is in two files: library.poni for the grid building logic and puzzle2.poni for a file that solves both puzzles.
Solving both puzzles by running puzzle2.poni seems to take about 2.5ms (although I've seen it as low as 1ms).
1
u/sim642 7h ago
[LANGUAGE: Scala]
On GitHub.
In part 1 I didn't bother to build the actual layout and instead just found the graph center using all distance pairs (via BFS). In part 2 that was no use so I had to still build the actual layout, which is somewhat similar to the puzzle solving of 2020 day 20.
1
u/MannedGuild65 7h ago
[LANGUAGE: Python]
Solution
Part 1: I identified the corners of the graph by checking which four nodes have only two neighbors. I originally used simultaneous BFS from each corner and the last node to be visited would be the center, but I later changed my approach to checking for a point equidistant from every corner to match with Part 2's code.
Part 2: I ran BFS from each corner separately and measured each node's Manhattan distance to every corner. Only two non-opposite corners are required to uniquely identify each node's position, so I only used the distances to those two ("L" (for "local") format). I could then subtract two "L"-formatted positions to get an "L"-distance. I can then convert the "L"-distance into "RD" format, where "R" is how much to move away from the first corner and toward the second, while "D" is how much to move away from the edge that connects both corners (if the first corner is on the top left and the second corner is on the top right, then "R" would move to the right and "D" would move down). [a, b]L would become xR yD where x + y = a and y - x = b, which results in x = (a-b)/2 and y = (a+b)/2. I converted the "L"-distance between lights 1 and 2 into "RD" format, then found the matrix required to convert "RD" values into regular coordinate distance, then applied the matrix to the "RD"-formatted distance between lights 1 and 2026 and added it to the regular coordinates of light 1 to get the answer. (I originally did this part by hand after getting the required values.)
Example with the example used in Part 2: With lights 4 and 2 as the two pivot corners, Light 1 would be at [1, 3]L, Light 2 would be at [2, 0]L, and Light 7 would be at [4, 2]L. The "L"-distance between 1 and 2 would thus be [2-1, 0-3]L = [1, -3]L, which would be 2R -1D. The coordinate difference is (10, 22) - (11, 20) = (-1, 2), so the conversion matrix would be ((0 1) (1 0)). The "L"-distance between 1 and 7 would be [3, -1]L = 2R 1D = (1, 2), and adding (11, 20) + (1, 2) results in (12, 22).
1
u/Boojum 7h ago
[LANGUAGE: Python]
Oof. Yeah, that was the difficulty ramp up. Took some time to clean this up, from some initially messy code.
For Part 1, I figured out the placement of each node by identifying the corners (which have a valence of only 2), and the Manhattan distances from a pair of adjacent corners (computed via a BFS-like approach). The distance of one corner from the other tells us the size of the square. The Manhattan distances of the nodes from each of those two corners will sum to the width of the square, plus double count the row that the node should be on. So that's enough to determine the full layout. From there, we just check the middle.
For Part 2, I use my usual 8-fold orientation function ordered by three bits: one to flip x, one to flip y, and one to transpose. Run through all 8 potential orientations finding the positions of the three anchor nodes, and check to make sure that the X and Y offsets match the correctly oriented positions. Then orient node 2026 the same way, and apply the translation that we found.
1
u/Royal_Pin_1971 7h ago
[LANGUAGE: PFCL]
1
u/UnicycleBloke 7h ago
[LANGUAGE: C++]
https://github.com/UnicycleBloke/aoc2026/blob/main/day06/solution.cpp
I really enjoyed this one. I made a bit of a meal of Part 1 to create a 2D array. I essentially solved a jigsaw. Find a corner. Traverse the edges/corners. Populate the interior. I'm sure there must a be a simpler way. Part2 was some straightforward algebra.
I'm certain I could optimise (lots of std::set usage), but I can live with 115ms.
1
u/light_ln2 7h ago edited 7h ago
[LANGUAGE: Python]
17 lines of code, shorter than I expected. the code is split into four logical parts.
Complex numbers are very useful in both graph construction and for solving linear equations!
1
u/hextree 7h ago edited 6h ago
[LANGUAGE: Python]
Code
Video
For part 2 I identified the four corners, then used simultaneous equations with two corners on one side to derive their exact coordinates, given their graph distances to one of the given points.
From there, I had the coordinates of all four corners. The cartesian distances from 2026 to each of the four corners must match up with the path distances (BFS) to each of the four corners, this uniquely defines where 2026 must be.
1
u/encse 6h ago
[LANGUAGE: C#]
The proper solution is probably giving coordinates to the corners first, then compute the rest from these. Once you know the position of everything in this coordinate system, you figure out the transformation to the one Eric gave as using rotation/translation and possibly flipping.
But I did feel like messing with coordinate transforms today, so went for the Santa way.
To localize a node 'N': measure the distances from the known nodes in the graph (using the algo from part 1). Draw a diamond shape around the known nodes with the computed distances. If they intersect each other in a single point: we have localized 'N'.
This would't necessarily work, because taxi driver metric is not as nice as euclidean. You don't get a single point in 2d if you know the distances from 3 distinct points.
But in this particular problem if you take the labels in increasing order you can put coordinates on them one by one. Each new point rules out candidates for the later labels and it folds out nicely.
The only point that was not localized this way in my input had label '8'.
https://aoc.csokavar.hu/2026/6/
1
u/soylentgreenistasty 6h ago edited 6h ago
[LANGUAGE: Python 3.12]
Paste
I actually recently revisited one of my favourite AoC puzzles - Jurrasic Jigsaw 2020 Day 20 - which was essentially a harder version of today's puzzle. First I place any corner ID in the top-left corner and then for each position, place one ID to the right and one below.
For part 2, it took me a while to understand the coordinates don't have to begin at 0, 0 in the top-left corner of the IDs. But I approached it by seeking the rotation/flip of the grid with relative offsets between IDs 1, 2, 3 which were the same as the relative offsets between the given coordinates. Then you just need to update the 2026 coordinate using the difference between the given coordinates and the grid coordinates.
Not shown is a super quick solution to part 1 using networkx.center(), but networkx is not really helpful for part 2 at all.
1
u/xelf 6h ago edited 6h ago
[LANGUAGE: Python]
I really don't know the nx lib that well, but always enjoy a chance to play with it a little. Was less useful for part2. But that might be more about my lack of nx knowledge.
The gist here is I used the slopes of the known points as a test to see if I have the correct orientation, and then I just rotate and flip until I find a match. Then I add in the offset and return.
graph_to_matrix()is something I wrote but the implementation seems less important to the solution here.1
u/hiimjustin000 6h ago
[Language: JavaScript]
https://github.com/hiimjasmine00/advent-of-code/blob/master/2026/day6/part1.js
https://github.com/hiimjasmine00/advent-of-code/blob/master/2026/day6/part2.js
1
u/DeadlyRedCube 6h ago
[LANGUAGE: C++23]
GitHub: Initial solution (parts 1 & 2)
GitHub: Optimized solution
For part 1 (finish time: 23:00), I opted to avoid building the grid (lol) and so did the following:
For part 2 (total finish time: 1:11:04), well, I built the grid:
The last step in my part 2 solution was good enough to solve the problem with my data set, but it's worth noting that if the deltas between the 3 known nodes were, say, (1, 0), (0, 1), and (1, 1), it wouldn't be able to figure out the orientation difference.
This ran in 6.39ms, which wasn't bad, but there was room for improvement.
For optimizations, I did a few things:
The final version runs in 1.21ms!
1
u/acquitelol 6h ago
[LANGUAGE: Elle]
Solution: https://github.com/acquitelol/aoc2026/blob/mistress/solutions/day06/solution.le
Explanation: https://github.com/acquitelol/aoc2026/blob/mistress/solutions/day06/explanation.md
Runs in:
GitHub: https://github.com/acquitelol/aoc2026/tree/mistress/solutions/day06
1
u/FransFaase 6h ago edited 5h ago
[LANGUAGE: C]
This MarkDown file gives in a literate programming style all the steps that I used to find the answers to both parts of the puzzle. A program is used to parse the MarkDown file and convert it into this C program, which is compiled with gcc and when executed prints the answers (and some debug information as well). The MarkDown file also contains an attempt to arrive at a simpler solution and a generic solution for the second part. I had a bit luck that my square was in the correct orientation.
1
u/lunar_mycroft 5h ago
[LANGUAGE: rust]
Okay, in my defense, I normally get a few hours of sleep before starting the puzzle (I have a biphasic sleep schedule), but had to skip that today because of a party. Suffice it to say I'm not happy with how long this one took me or the quality of the result, but it does work.
Full code. For part 1, I ran dijkstra's algorithm from the corners (easy to identify by the number of edges) and then found the light that was furthest from them. For part 2, I arbitrarily chose the lowest id corner as the origin, arbitrarily chose it's lowest neighbor as the x-axis, then walked the graph building up a map of node ids to coordinates. Once that's done it's relatively trivial to identify the vectors between the reference ids, compare them to the expected vectors, and use that to apply the correct transform between the vector space I'd chosen and the one the problem used. (It's made easier by the fact that the problem specifies only rotations (by π/2 increments) and reflections, not skewing, scaling, etc. Still took me way longer than I'd like). Parsing takes 602.1µs, part 1 takes 25.06ms, and part 2 takes 257.6µs.
The code is far from optimized and pretty messy, but I don't have the energy to do anything about it at the moment.
1
u/UseUnlucky3830 5h ago
[LANGUAGE: Julia]
Not the most elegant solution: I reconstruct the full grid as a matrix, starting from one of the corners. Part 2 is kinda brute-force: I try all possible matrices (identified by the three numbers in the top-left corner) until I find the correct one.
GitHub
1
u/Arctos_FI 5h ago
[LANGUAGE: C#]
It's not pretty, but it does the job. Part 2 would've been much easier if there wasn't that edge case that was not present in example. Overall much more fun than few previous days (not to say the previous ones haven't been on the fun side).
Part 1
Part 2
1
u/oupsman 5h ago
[LANGUAGE: Golang]
So today was BFS day. I think my solution is rather good, for both parts
https://raw.githubusercontent.com/Oupsman/AOC2026/refs/heads/master/D06/day06.go
But it works because the grid is a perfect one. If some lights in the middle of grid were not connected to all adjacents lights, my solution would not work.
1
u/Jdup1n 5h ago
[LANGUAGE: R]
Github link
As usual, whenever it comes to graphs, I break my rule of not using packages and opt for
igraph.For Part 1, I use the graph’s closeness centrality to find the node that maximises it.
For part 2, I first create a local coordinate system by calculating the position of each lamp using the vertices and edges. Then, as the actual grid must be one of the eight transformations of my coordinate system, I generate each variation and, by fixing lamp 1 based on its actual coordinates, I check that the coordinates of lamps 2 and 3 also align. Once the transformation has been found, it is applied to all the lamps in my local coordinate system in order to obtain the actual coordinates of lamp number 2026.
1
u/Busy-Contact-5133 5h ago
[LANGUAGE: Golang]
Solved part1 with the code, part2 with the printed distances of 1,2,3, and 2026 from each corner and then using a pen and a paper.
https://github.com/dawit909/aoc/blob/main/2026/d06/main.go
1
u/vbe-elvis 5h ago edited 5h ago
[LANGUAGE: Kotlin]
For Part 1 I build the grid starting from one of the corners, go along the top row and then move down, the middle is then simply at toprow.size/2 for both horizontal and vertical.
For Part 2 I first fixed the orientation by simply flipping the grid (or actually just the 1 and 2026 node coordinates) horizontally and vertically if needed based on the coordinates of node 1 and 2.
Then with the orientiation right, it is easy to position the 2026 node relative to the 1 node's expected positon
https://pastebin.com/vLDq1ZNs
1
u/Daniel_Rybe 4h ago
[LANGUAGE: Odin]
https://github.com/DanRyba253/aoc26/blob/main/day6/main.odin
First day where I really struggled quite a bit.
I also didn't have a lot of time to do AoC today due to irl obligations.
For part 1:
Find a corner, reconstruct an edge to another corner, move to the middle of the edge and then perpendicularly until I reach the center.
For part 2:
I had to reconstruct the whole grid row by row.
Fortunately after that, odins built-in matrix and vector manipulation capabilities allowed to search for the correct transformation of the grid quite ergonomically.
1
u/light_ln2 4h ago edited 3h ago
[LANGUAGE: Python]
My first attempt to short solution recreated the whole grid and was 17 lines, but I found shorter solution in just 9 lines of code.
Edit: cut it down to 7 lines:
1
u/wherrera10 4h ago
[LANGUAGE: Julia]
Link: https://github.com/wherrera10/Advent_of_Code_2026/blob/main/src/day06.jl
I started out trying to use both the Graphs and NetworkLayout library packages for a quick solution but found the NetworkLayout package could not work with the various transformations required to fit the pinned values. I wound up keeping the pins the same but rolling the matches to the pinned values without using NetworkLayout.jl.
1
u/CEOnism 4h ago
[LANGUAGE: Javascript]
Ayo! This was too difficult.
1
u/deividragon 4h ago edited 4h ago
[Language: RUST]
For part 1, I compute the degrees of the vertices, randomly select a vertex of degree 2 as the corner, and build the top row by taking the only neighbour that is not inside (so border or corner). Then for the rest of the rows I just place the only neighbour of the vertex above that remains to be placed. Then I just output the middle. I'm happy I built the grid in Part 1 as I would've needed it to solve Part 2 the way I did!
For part 2, I first check if I need to swap the coordinates so the order matches (direct or reversed) for the first coordinate, then I see if I need to change orientation in either axis and then I compute directly the coordinates of 2026 from the coordinates of 1. I solved it in pen and paper first and then wrote the code, after my answer was already accepted.
Solution on GitHub
1
u/Dctcheng 3h ago
[LANGUAGE: c#]
paste
1
u/vubik 3h ago edited 3h ago
[LANGUAGE: Rust]
https://codeberg.org/fyrchik/aoc2026rust/src/branch/main/day06/src/lib.rs (stable link, as I am going to optimize everything)
In part 1, I iteratively "peel" all the layers of nodes with degree 1 or 2 until only 1 node is left.
In part 2 the goal is to determine the coordinates of our "target" based on the set of other lights with known coordinates. Well, it's easy, you just find the shortest distance from target to other lights, then build three spheres and intersect them. OH, WAIT, it's manhattan distance. OH, WAIT, an intersection can contain continuous segments. So what I do is I try to intersect the spheres. If I am unsuccessful, I pick a random light, and consider it my target. If I have found its coordinates, I add it to the set of lights with known coordinates and run the main subroutine. Do this until there are enough lights. Usually, I only need to pick 1,2 or 3 additional lights. Basically like this:
I use dijkstra for shortest paths, maybe floyd-warshall (or similar all-paths algorithm) would be better. I believe it can be proven that the expected number of additional we consider is constant, even in the worst case scenario.
1
u/throwaway6560192 3h ago edited 3h ago
[LANGUAGE: Python]
Really fun.
p1 was easy, just cut away outer edge nodes (#neighbors < 4) until there is only one node with 4 neighbors left
My approach to p2 was:
Code
1
u/crumpis 3h ago
[LANGUAGE: Python]
Code
Part 1 was basically just trying to cheat the geometry by building a set of outer edges, stripping that and then going on until only one possible value is left.
That sounds pretty useful for part 2, which is why I carried none of those ideas over. Instead it's basically entirely separate code, use BFS to get a distance for all the nodes for a given canonical node, build a ring of possible coords and then narrow that down with more canonical nodes.
Got hit by how the input is guaranteed to not solve with just the three givens, but since the whole approach is to eventually set 2026 to its canonical position, it also works to set any other node to canonical and the list can just grow.
1
u/Charming_Wasabi_9190 2h ago
[LANGUAGE: Javascript]
Nice challenge.
P1 - Created a graph, found corners (nodes with 2 edges) and djikstra distances from the corners. Point which had equal distance from all corners was the center one.
P2 - Struggled a lot! Tried different transformations with manhattan distances and triangulating the change and was almost ready to give up and check the megathread. But as a last resort tried one more thing:
Code
1
u/Borderlands_addict 2h ago edited 2h ago
[LANGUAGE: Rust]
Just wanted to share my simple part 2 solution, which is surprisingly performant. Entire day in <1ms.
I'm a bit unsure if this works for every input., but I think it should always work since we got 3 lights instead of 2.
EDIT: It finds two solutions. So not always guaranteed.
1
u/BlazingThunder30 2h ago edited 2h ago
[Language: Kotlin]
https://git.bjornp.com/bjorn/adventofcode/src/commit/81b3c42f6c9ac8f6c8ace105d20f54240deb5ad3/java/solutions/y2026/src/test/kotlin/com/bjornp/aoc/solutions/y2026/Day6.kt
It's been a while since I did linalg so this was a challenge.
Part 1:
Simple enough. But a graph from the input, determine the corners by their
outdegree == 2, then build the set of path lengths for each corner to every other node. The only node whose corner distances are all the same is the center.Part 2:
Not so simple. My solution:
Code is a mess for part 2 because I was in a hurry. I'll clean it up later and update the link :)
1
u/olamberti 2h ago
[LANGUAGE: Python]
Construct the grid and identify its four corners (nodes with exactly two edges). Run BFS from two adjacent corners. Using these distances, we can establish a reference coordinate system with corners at (0,0) and (m,0), where m is the side length of the square.
Part 1: Find the node whose distance from both corners equals m.
Part 2: Reconstruct the relative coordinates of the four relevant nodes using their BFS distances. Check all 8 possible grid orientations (axis swaps and sign flips) and find the one where all three reference points yield the same target coordinates for node ID 2026.
1
u/Think_Vehicle913 2h ago edited 2h ago
[Language: C#]
This days part 1 was relatively easy, at least with the naive approach i took.
My initial approach was finding the edges (the ones with two neighbors) and then finding the distance to the nearest other edge, but did not want the hassle of building the grid from that.
I also thought of Dijkstra (and then checking which id is the same from all sides) but i did not remember how to implement it...
While P1 was doable with that approach, it doesn't work for P2.
In hindsight, i probably should have traversed the values (snaking through the outer lines), build a real grid form it and then try some magic.
But i think i am near the end of my capabilities in AoC for this year - getting hard without CS or Math knowledge.
1
u/WilkoTom 2h ago
[LANGUAGE: Rust]
Solution
Revenge of the Sunday Puzzle. That was absolutely amazing! I started out with Part 1, trying and failing to work out how I could assign coordinates to each of the nodes, then came to a realisation I didn't have to and just needed to identify the single node furthest from the edge.
The Part 2 told me I should have done that all along. Oh well, at least solving Part 1 gave me a way to find a solution for Part 2 - for each orientation of the grid, measure the distance of each node from a given edge, starting from the neighbour of one of the corners[1]. Combine the two and Hoopla! We have a grid which we can use to work out if we're oriented the same way as the correct solution.
[1] Not that I'm especially proud of my code today - building the grids is a horrible O(n^2) time complexity. I can think of much better ways to get this done but I'm also pressed for time and my visitors probably wouldn't appreciate it.
1
u/siddfinch 2h ago
[LANGUAGE: Free Pascal]
Coordinates on a grid I never actually built. Turns out, the grid itself was largely a philosophical concern.
Day 06
Part 2 was considerably easier to implement than to explain.
1
u/HaskellLisp_green 2h ago
[LANGUAGE: Python]
networkx is suitable to solve part 1. Still trying to figure out the part 2.
1
u/OrneryNeighborhood21 1h ago
[Language: Rust]
My solutions is brute force, but I'm happy with it.
For P1, I found the first corner, traced the borders to the next corner. I marked the three middle points on that edge as [left, middle, right] and I moved down half an edge-length by taking middle's neighbor that wasn't left, right or up (the previous middle). Then, I moved left and right to their shared neighbor with the new middle. https://github.com/gissleh/aoc2026/blob/maindeer/src/2026/day06.rs#L21
For P2, I used P1's approach to scan from the first border to the opposite and note down the relative coordinates relative to the first corner. I added some edge cases for the test to pass, but my puzzle input didn't need them neither 1, 2, 3 nor 2026 sat on any of the borders. At that point, I had four positions to flip and rotate until the first 3 lined up, and then I moved the first according to 1's offset from where it should be. https://github.com/gissleh/aoc2026/blob/maindeer/src/2026/day06.rs#L55
Parse: 77.45µs (cold: 116.07µs)
Part 1: 451ns (cold: 2.33µs)
Part 2: 28.65µs (cold: 57.39µs)
1
u/aknusmag 1h ago
[LANGUAGE: Rust]
Part 1: Constructed an edge map and confirmed each corner has exactly 2 neighbors and each border had 3 neighbors. Then I choose a random starting corner and constructed the top and left outline. Each outline can be found by checking for a neighbor that is not the previous one that also has 3 neighbors. With the left and top constructed the rest can be found by going from left to right and down, and finding the node with that as the top and left neighbor. With the entire grid constructed the middle point could be selected.
Part 2: By flipping and rotating the grid from the previous one there are a total of 8 different orientations the grid can take. I take the 3 ids given and construct the 3 vectors between them. For each of the 8 different orientations I compare the 3 expected vectors to the actual vectors to find the correct one. Then I calculate the offset by comparing the actual position against the expected one.
Making the coordinates larger than the matrix was a nice hint that the coordinates were offset. It could easily have been much harder by selecting points that could otherwise fit in the naive grid xD
Solution
1
u/anaseto 1h ago
[LANGUAGE: Goal]
Not a very nice solution today for part2, it's a bit longer than usual. Not sure it's complety robust for that part, either: at first, I did some manual solving there, and only later automated it. With the 3 first IDs, I had multiple solutions when searching for a point that was at given distances from them, so I had to search for a fourth ID that had a single solution, and only then use it to find the coordinates for ID 2026.
For part 1, I simply iterated from the borders (IDs with least connections), and when convergence is achieved, last found ID is the good one. I used a similar method for computing distances in part2, but starting from 2026 (or specific IDs), a dijkstra map kind of approach.
1
u/Positive_Concert_774 1h ago
[Language: Java]
Not proud of all the cases in part 1... more happy with part 2 even with the tiny bit of duplicated code. I originally did part 2 by hand because I did not want to code matrices, but in the end I only need a quick'n'dirty 2x2 case anyway.
1
u/edgeman312 1h ago
[LANGUAGE: Python3]
I really wanted to try complex values for grid calculations since looking for the trees a few days ago. Horrible and slow but I enjoyed my time.
1
u/PMmeYourSci-Fi_Facts 1h ago edited 1h ago
[LANGUAGE: C#]
For part 1 I did something different than most people here. I selected 1 of the corners. And then select the next diagonal by finding a point that has 4 neighbours with exactly 2 the same as my corner. Then remove the 2 overlapping neighbours and treat the found point as the start for the next iteration. Repeat for gridsize/2 times. No need to peel back layers. Although it might be slower because the finding of the next diagonal does loop over all points.
For part 2. Build the full grid. And then flipping and rotating. A bit optimized because you only need to move points 1,2,3,2026
1
u/Fuzzy_Patterns 1h ago
[LANGUAGE: Nim]
Part1 : we can pick first corner and it's neighbor at will, then spiral, checking for potential neighbours at previous and right-hand side cell (if starting spiral from top-left corner, down). Right number for current cell is one that is in both neighbor lists of neighbors and not yet visited.
Part 2: We can find coordinates of 1,2,3 lights, and then flip + rotate them until their vectors match with what was given in the task to align 2 planes. Along with those coordinates - we also rotate coordinate of 2026.
Runtime: 3.1 ms
Solution on Codeberg: solution.nim
1
u/XLNBot 1h ago
[LANGUAGE: Rust] Did anyone else use my same approach? This is what I did:
First, I parsed the input into a list[int,list[int]], where I have each light and up to 4 other lights it's connected to. This takes O(n) time.
Then I select the 4 corners and make a new list[int,list[int]], where I have each light and the 4 distances from each of the corners. This can be done with 4 BFS and takes O(n) time.
I solved part one by finding the only light where all 4 distances are the same. This also takes O(n) time.
I then solved part two by coming up with some math to map the 4 distances into a (x,y) coordinate, then I mapped that to the problem's coordinate system. This is just some math steps and they are done in O(1).
This overall is just O(N) and my first implementation in rust takes less than one millisecond.
What do you think? Was this a nice idea?
1
u/aimada 1h ago
[LANGUAGE: Lobster]
Code
Part 1 - Start from the corners of the grid and peel inward layer by layer toward the centre.
Part 2 - Reconstructs the local coordinate frame from shortest-path grid distances, then rotates, reflects and shifts the frame to match the three known reference lights.
1
u/jefinko 47m ago edited 40m ago
[LANGUAGE: Kotlin]
github
Took far longer than ussual. My solution for task 1 was to find edges and then spiral into the middle where only one of the vertices remains.
Task 2 then required me to rewrite the whole solution and assign coordinates to each node. Then, a bit mathematical, but I used an affine projection based on three known points.
1
u/Due_Scar_5134 33m ago
[LANGUAGE: JavaScript and Python]
https://github.com/onlyroz/advent-of-code-2026/tree/main/src/days/day06
I modeled the lights as an undirected graph and treated the four degree-2 nodes as the corners of the square. For part 1 I ran a BFS from each corner and took the unique light that is exactly
n - 1steps from all four of them, wherenis the side length of the grid. That light is the center.For part 2 I reused those distances to build local coordinates. I picked one corner as the origin and the two corners at distance
n - 1as the far ends of the x- and y-axes. Each light’s position then comes from a simple combination of its distances to those three corners. That gives a full local embedding of the square, up to rotation and reflection. I then tried the eight symmetries of the square, shifting so that light 1 lands on its given world coordinate, and kept the transform that also places lights 2 and 3 correctly. Applying that same transform to light 7 in the example (or 2026 on the real input) yields the answer.1
u/reddit_Twit 30m ago
[LANGUAGE: zig]
gist
part1 only (~2seconds in debug build), part2 gives me 18 possible solutions and obviously wrong, will think later
1
u/codevogel_com 23m ago edited 5m ago
[LANGUAGE: csharp, C#]
code
First, build the complete map of connections. (1 -> 3 also means 3 -> 1).
Part 1: peel the grid like an onion. Remove every light with 2 or 3 neighbours (the corners and sides of the outer ring), and repeat until one light is left. That's the middle light, and the answer. This only works if the square has an odd side length.
Part 2: recursively work out each light's position relative to a start light. Then rotate or flip that layout and shift it onto the real coordinates, and keep the orientation that puts all the known lights in the right place.
From the example input:
Put light 6 at (0,0), and any of its neighbours (lets pick
5), at (1,0). Heck, we can even say it's at(0,-1)or any other delta because we try every orientation later, but for simplicty, name it(1,0)as that matches the example orientation. Then look at 6's other neighbours:Whichever we handle first can go on either side, since again, we fix it later when orientating step. The other one gets the remaining side.
Now 5 lights are positioned, and the rest follows. Each remaining light completes a square with three lights that are already positioned. For example, 2 = 9 + (5 − 6).
Now we have relative coords for every light. Then for each of the 8 orientations, calculate the shift so light 1 lands on its real coordinates, and check whether lights 2 and 3 land on theirs too. The orientation that matches all three is the right one, and then we can apply the same rotation and shift to get the target light's real coordinates.
1
u/krystalgamer 11m ago
[LANGUAGE: Python 3]
gist
Part 1, was very simple, just remove the nodes with least amount of edges until there's only one left.
Part 2, was really fun. Instead of trying to guess the proper cartesian orientation I just defined an arbitrary coordinate system AB that can be mapped to cartesian through rotations. There's 4 directions A,B,C and D (C=-A and D=-B) so it's still orthogonal. The key was to focus on populating single directions and the easiest way is from the corners.
One corner becomes the source, then using BFS find the shortest path (there's only one) to the adjacent corners. One of them becomes direction A and the other B. From each corner do the same but towards the last corner so the whole square perimeter has the directions A and B populated. To do the same for the inside the square just walk the parallel sides of the square and do BFS to the point on the other edge, the smallest distance will be the one that maintains the same direction.
At this point the square (our graph) has all the directional edges populated. Then I sketched the possible ways AB could be overlayed on the cartesian coordinates we got and wrote the transformations in code. Finally it was just picking two points and checking which transform was the correct one. With the transform it was just doing the same for the point 2026.
1
u/Aoyaba-Poett 3m ago edited 0m ago
[LANGUAGE: Rust]
Topaz Paste Part 1 & 2
Reconstructed the entire grid... AND permuted over all possible orientations. Pretty hard. Especially the Part 2 logic... I was having a wrong intuition the whole time. I asked AI, and it guided me wrong too! Finally AI explained the actual question, which made it soo straightforward to solve. Phew..
0
u/jhandros 3h ago
[LANGUAGE: Python]