Discussion thread for day 3 of the Advent of Code - https://adventofcode.com/2025/day/3
I've tried to do one every day! 🤣 (BTW, @clmc9601, have not got the macro working for Day 2, but maybe I'll send it your way and you can have a look?)
My solution!
I read everyone's solution, but there are many ways!
My way:
Workflow :
The mission to avoid using macros until absolutely have no choice continues 😂
At this rate, the mission won't make it past tomorrow!
Day 3
Initially tried a macro, but it would have blown up my computer, so after a chat with @robbinrv I thought of another approach. The real nice thing about this is it works for both parts (or any number of batteries) based on a single config
I must admit, I peeked at some of the posted solutions because I got a little stuck. And then I quickly realized that my brain does not work like the geniuses that posted before me....Oh well. Somehow rather I made it through!
I did use an Iterative macro for part two because I'm basic. And also I'm not playing tool golf.
Similar Macro solution to others.
I default to Iterative Macros for AOC solutions because they map to how I think about problems, so no surprise that was my route here.
I will note that CoG's solution below is absolutely glorious. I'm so keyed on the AOC problems that lock up your computer when you try to solve them directly that I didn't even consider the idea of data expansion to allow for a dynamic programing solution. Solutions like this tend to run in N^2 or worse time, so be careful with them when things get larger, but revel in the mathy goodness until then.
In lieu of a proper writeup, here are some things that I had to debug out of my macro for anyone struggling:
Data type. I'm just old enough to have been taught to use minimal data types to optimize storage. That is no longer a reasonable paradigm. Just use INT64 for everything and make sure your macro isn't converting. I just throw a select at the beginning to force the data types.
Adjusting how many batteries to check. I initially missed that after checking N batteries if I selected anything except the first, you have to reduce N by the Position-1 of your selection. Think of this as spending your budget of ignored batteries. Sum->CountNULL helped here.
Join->Union pattern for preserving data grain. To implement the adjustment to the number of batteries to check each iteration, I was joining the CountNull back with the original data set. Problem here is that after some number of iterations there were no NULLs, so the join output wasn't sufficient, I also needed the unjoined Left. So join, union back, turn off the field warning on the join. Patterns.
A side note there that it helps to be consistent with Join inputs. I build joins such that the Left is always the data set and the Right is the new thing being added. That way I can think of preserving record count on Left+Join as a basic test of join logic.
