AoC 2025 Day 1

It's a bit of a late start, but this year I finally got around to trying Advent of Code.

Part 1

This part was pretty easy. I split each line into the direction (represented by -1 for left and 1 for right) and number of dial clicks, then multiplied them together and added to the previous dial number. After using the modulo operator if the dial went out of the 1 to 99 range, I tracked how many times the dial was at 0.

Part 1 Solution

Part 2

Here I made 2 major bugs

Fist, I assumed that in every turn of the dial, it would only pass by 0 once. I started off by checking if the dial was already at 0 to prevent double counting, then incrementing the counter if the dial went out of range and was not already at zero.

for line in input:
    direction = -1 if line[0] == "L" else 1
    num = int(line[1:])
    already_zero = dial == 0
    dial += num * direction
    if (dial < 0) or (dial > 99):
        dial = dial % 100
        if not already_zero:
            num_of_zeros += 1
    elif dial == 0:
        num_of_zeros += 1

After rereading the task I realized that I missed the final paragraph

"Be careful: if the dial were pointing at 50, a single rotation like R1000 would cause the dial to point at 0 ten times before returning back to 50!" I changed my approach from adding the number of dial clicks all at once, to incrementing or decrementing it by one and checking if it went out of range.

My second mistake was a classic off by one error. I forgot that the python range end number was exclusive, so I needed to change range(1, num) to range(0, num).

Part 2 Solution