Overview⌗

I’m going to as much of AoC 2026 in SQL as I can. I’m posting my solutions here. I’m just going to update this post daily with my thoughts and things I learned as I go.

I don’t know how far I’ll get. I’d like to do at least 6 days of it, but we shall see.

Setup⌗

I’ve written a small function in get_data.py that pulls in each days' data into a csv. It’s a little messy, but I think it’ll work fine for what this is.

Each day I’ll just have a file under sql_solutions that contains the SQL for solving the problems.

I’m using duckDB to directly scan the csv’s and query over them. I’ll be avoiding UDF’s and attempting to only do this with sql. I’m sure recursion will come in handy.

Day 1:⌗

Straight forward, just used the PRODUCT() function multiply top and bottom 3.

Day 2:⌗

Definitely a step up in trickiness. I joke a lot about cross joins on my linkedin profile, but they are helpful. I hadn’t used REPEAT() to dup a string, I’m sure there’s a better way to generate the pairs than how I did it becasue I end up having to do a WHERE DISTANCE <=6 GROUP BY ALL to get what I want, but it works.

For star two I take the whole string and throw it into individual rows and then basically enact my will in a CASE Statement. Logically it works, but I’m basically hard coding what needs to happen rather than actually sorting the list. I got the answer and its all SQL so… shrug…

Fun day!