Published December 03, 2025
It's day 3 of the 2025 Advent of Code and we had another fun puzzle. For today parts 1 & 2
were the same algorithm, just different lengths. We were given a list of banks of batteries and had to find the n largest batteries
in each bank in the order that they appear. For part 1 we needed 2 and for part 2 we needed 12.
For part 1 I didn't really think about doing a generic solution (I should have) but I was able to get it relatively quickly with just
a few errors (no incorrect submissions) until I finally understood what the problem was. As soon as I saw part 2 I knew I needed to
refactor my part 1 solution into a general solution, so that's what I did. I started by creating a dictionary with a key of the number
and a value of a deque of the indices.
indices = defaultdict(deque)
for i, n in enumerate(bank):
indices[n].append(i)
I then sort that, reversed, so that I can proces the numbers from high to low. Next, I loop size times to find the correct digit
for each spot.
One of the things I'm glad I did at the start was create a class to handle this. Its __init__ actually does the heavy lifting
and it has a __add__ and __radd__ so I can easily do the math part at the end. This makes my solve function a simple one-liner:
def solve(input_: str, count: int) -> int:
return sum(BatteryBank(size=count, bank=line) for line in input_.strip().splitlines())
Check out the full solution at https://github.com/brass75/AdventOfCode/blob/main/aoc_2025/day3.py.