Published December 10, 2025
Day 10 is mean. It's nasty. It's ugly. It requires higher level math that I never studied.
Part 1 was simple enough:
def check_toggles(machine: dict) -> int:
for n in range(1_000_000):
for combo in itertools.combinations_with_replacement(machine['buttons'], r=n):
lights = [False for _ in range(len(machine['lights']))]
for toggles in combo:
for index in toggles:
lights[index] = not lights[index]
if lights == machine['lights']:
return n
return 0
Nice, easy, very understandable. Might not be the most elegant or efficient solution out there but it gets the job done.
Part 2 could work with essentially the same algorithm, just checking the "joltages" instead of whether the lights are on or off but the scope of the data is so large that running it would essentially be a heat death of the universe solution. I decided to seek inspiration in the solutions megathread and it looks like almost everyone used either SciPy or Z3 to solve it. I decided to, essentially, copy this solution since I've never used either SciPy or Z3 before. It works. It gives the right answer. But I am very much not satisfied with it since I didn't acatually learn anything. I did look at the "no import" solutions that some people had posted but they rarely used reasonable variable names or comments so trying to follow along, when I don't understand the math involved, makes it impossible for me to actually understand what they're doing. Since the ostensible goal of my doing this is to actually learn and understand why a given solution works, that might get me the ⭐️ but that's it.
In any event, I did post a solution and get the ⭐️ and you can see it on GitHub.