Discussion thread for day 3 of the Advent of Code - https://adventofcode.com/2025/day/3
The 1st day we need Iterative Macro, I think.
@gawa Day 3 going iterative does seem early... but who knows what will happen with a 12 day AoC this year?
throw all to multiple-row tool. 800+ chars. glad i know excel to help.
formula if you interest
if length([row-1:max])<12 then [row-1:max]+[data] else max(tonumber([row-1:max]), tonumber(Substring([row-1:Max],1,12)+[data]), tonumber(left([row-1:Max],1)+Substring([row-1:Max],2,12)+[data]), tonumber(left([row-1:Max],2)+Substring([row-1:Max],3,12)+[data]), tonumber(left([row-1:Max],3)+Substring([row-1:Max],4,12)+[data]), tonumber(left([row-1:Max],4)+Substring([row-1:Max],5,12)+[data]), tonumber(left([row-1:Max],5)+Substring([row-1:Max],6,12)+[data]), tonumber(left([row-1:Max],6)+Substring([row-1:Max],7,12)+[data]), tonumber(left([row-1:Max],7)+Substring([row-1:Max],8,12)+[data]), tonumber(left([row-1:Max],8)+Substring([row-1:Max],9,12)+[data]), tonumber(left([row-1:Max],9)+Substring([row-1:Max],10,12)+[data]), tonumber(left([row-1:Max],10)+Substring([row-1:Max],11,12)+[data]), tonumber(left([row-1:Max],11)+Substring([row-1:Max],12,12)+[data])) endif
I used an iterative macro.
Dynamic Non-Macro Solution! Since I started quite late and had a strong feeling this was possible without a macro, I took my time and built this solution.
Happy Solving!
Initially, my solution generated way too many records.
I was initially unsure how to structure the logic for P2. However, once I understood it, the workflow proved to be less complex than I first thought.
- P1The general idea was to select the largest digit from the right side of each position to create a two-digit number, and then select the largest among those.- P2
The specific logic for P2 is as follows:
To determine the 1st digit (from the left):
To determine the 2nd digit:
To determine the 3rd digit:
This process is repeated in the same manner for the subsequent digits.
Finally, the 12 extracted digits are concatenated to form the resulting number, which completes the process.<P1 Batch Macro><P2 Itterative Macro>
Started off part 1 by building an array. This would probably brute force part 2, but was taking too much time and laptop to finish.
Refactored into a more optimised solution that I could build into an iterative macro for part 2.
Day 3 done! I knew as soon as I started Part 1 that there'd be a Part 2 along those lines... but that didn't stop me getting a quick star before reevaluating my life decisions. Went down the macro route like most others for P2 - took a little while to figure out the logic and troubleshoot my filtering but got there in the end! A fun challenge!
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!
Forced myself to do an iterative macro. Thank you AoC for strengthening my skills!
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.
I really love Macros. Was able to nail it first time between nailing Sample data versus Real Data.Part2 Macro captured some Part1 concepts, of course, but expanded to find any quantity of digits you set. So when I set it up to only 2 digits it solved part 1 too.
Day 3 complete! Cool challenge that definitely scaled up from part 1 --> part 2. Honestly, at this point, I am just happy to still see my name without scrolling on the leaderboards because these are tough!! See you all tomorrow😀
My Solutions:
My Reflection:
First day with a macro, and the workflows are certainly growing too! In terms of which part was most challenging, I found this one the opposite of yesterday's. I had an idea early on, but it took a little while to build the solution. Looking forward to tomorrow's challenge!
2) Choosing the battery sounded straight forward enough but then I realised, I needed to make sure I had at least, one battery to the right of my chosen battery, in order to ensure I could make the full bank, of 2 batteries. With this in mind, if I temporarily remove the last battery from my list, then I don't need to worry about having enough left, as I have the temporarily removed one in "reserve". To remove this battery, I took the maximum position ID from the list, then filtered out any battery with that ID.
3) Now with enough in reserve, I can freely choose, the largest battery, from the remaining list. I used a sort descending and then a sample tool to achieve this.
6) Finally, we need to combine the first and second battery values together to get the Joltage per bank. Then simply sum the Joltage to get to the answer.
Although the steps in the iterative, are almost identical the steps 2- 4 above, Ill briefly explain the changes. 1) In the original step 2 above, we removed the bottom battery from our list, and kept it in "reserve". This allowed us to choose the greatest battery value, from those that remained. As we are now working with a 12 batterie bank instead of just 2, we need to keep more in reserve. For the first iteration, we need to keep 11, batteries in reserve. Then 10 are reserved in the second iteration, and so on. I achieved this by making a small adjustment to the filter tool, using the engine iteration number.
2) Step three from above, is exactly the same inside the macro, as it was out. The next difference is simply with the outputs. After step 3 is complete, we have found the best battery per Line ID, so this is then output from the macro. Like before, the list of batteries is then filtered down so we have only those that appear to the right of the previously chosen batteries. However, at this stage I have also added a statement to remove all records from the loop, on the 12 iteration.
3) Out of the iterative macro, I then get a list of all the chosen batteries with their Line IDs and Position IDs attached.
4) I used a sort and summarise tool, to concatenate these individual batteries, back into their corresponding banks (Line IDs).
5) Finally, like in part one, the Joltages are summed to arrive at the final answer.
I reworked my copy and paste mess to use an iterative macro. The macro works for both parts.
My first macro in AOC 2025. Unfortunately.
This is where the difficulty really ramped up for me.
I solved part 1 with some effort, but not too bad. Then I got to part 2 and got totally in my head. You ever have it where you start with something and then just can't get that idea out of your head and it ends up getting in the way? Well that's what happened to me. Part 1 was obsessively in my head to the detriment of thinking through part 2.
In the end, I studied up on a variety of other's solutions for part 2 and ultimately adapted @gawa's iterative macro (credit where credit is due). Thank you and nicely done gawa!
Here's my solution. No narrative this time around, my brain is fried after this plus the day job...
... on to day 4...? 😅
AoC 2025 Day 3 part 2 tool golf.
Was able to solve part 1 and I could swear my part two works... but it doesn't yet...
Your answer helped me a ton, @Qiu. Still trying to process part 2 but man I've learned a whole lot. Tile seems like such a helpful tool!