Advent of Code Day 6

Published December 06, 2025

It's the sixth day of Advent of Code 2025 and it was a frustrating one. This one I can't blame on the problem, although it was tricky to understand. This one I can blame on PyCharm. In a puzzle where whitespace really matters my IDE decided to strip the whitespace off the ends of some of the lines of the puzzle input. This led to me having a solution that worked give the wrong answer because the input data was corrupted.

In part 1 we had to some basic math. The input data was space separated columns with numbers and the bottom row being either a + or a *. Apply the operator from the bottom to all the numbers above it to get the answer for a column and then add up those answers to get your first star. Pretty easy. I made a do_the_math function that took the operator and returned the sum or product of the operands as needed:


def do_the_math(op: str, nums: Iterable[int]) -> int:
    return math.prod(nums) if op == '*' else sum(nums)

In part 2 we were told that the numbers were on their sides and need to be rotated so:


123 328  51 64 
 45 64  387 23 
  6 98  215 314
*   +   *   +  

should actually look like:


1   369 32  623
24  248 581 431
356 8   175 4
*   +   *   +  

So I went about modifying my parsing to preserve the whitespace - I decided to use regex because I'm pretty familiar with it. After a bit of trial and error I got something that worked on the test data and gave me an answer for the real data. But it was wrong. OK... Let's see if we can figure out what's going on, tweak it. I spent a while banging my head against it before I went to Reddit to look for alternate approaches. I saw one that I understood (I want to get an idea, not a solution) and started to implement it. I got a different number - in the correct direction! - but still wrong. OK... Let's keep trying. I looked at a different approach from Reddit and tried that and yet another wrong answer.

OK. Time to see if the problem isn't with the coding but somewhere else. So I looked at the test data. Now, I should probably describe my usual workflow. I open up the test data in the browser and paste it into a new file in PyCharm. That's it. Simple and easy. Apparently PyCharm decided to strip off the whitespace at the end of lines which changed 2 of the values I was using. OK. I'll manually add the ' ' back in and save it. Didn't help. Went back to the page and did Save as for the test data and overwrote the file that had been open in PyCharm and suddenly it works.

Now with a working solution in hand, I went back and tried my original solution again. Lo and behold, it works. So the solution you see today on my GitHub contains both the solution I implemented based on the Reddit comment above (since that's a much faster solution that's the one that actually runs) and the regex solution I finished hours earlier.


Previous: Advent of Code Day 5 Next: Advent of Code Day 7