Advent of Code 2025 - Day 1¶

In [1]:
# Open the input and read the input into an array of strings
with open("aoc_2025_d1_input") as f:
    lines = f.readlines()
print(len(lines))
4499

Part 1¶

Part 1 requires us to turn a dial numbered 0 through 99. The instructions tell us to turn the dial right (increase the number) if the line starts with an "R" and turn the dial left (decrese the number) if the line starts with "L". This is secretly adding and subtracting in modular arithmetic.

The output is the number of times we reach exactly 0.

In [2]:
# Counts the number of times we reach 0
zero_count = 0

# The dial starts at 50
dial = 50

# Loop through the input
for l in lines:
    # If the line starts with "R", add the digits to the counter (modulo 100)
    if l[0] == "R":
        dial = (dial + int(l[1:])) % 100
    # If the line starts with "L", subtract the digits to the counter (modulo 100)
    elif l[0] == "L":
        dial = (dial - int(l[1:])) % 100
    # If we don't have "R" or "L", something has gone wrong
    else:
        print("Incorrect input")
    # Increment the zero_counter if the dial reads 0
    if dial == 0:
        zero_count += 1

# Print the output
print(zero_count)
1145

Part 2¶

For Part 2, we need to count every time the dial passes a 0. The code to update the dial won't change, but the logic of updating the counter will.

The problem statement warns us that we may have to pass 0 several times during a single turn. This warning works as a hint on how to solve the problem.

In order to count the number of times the dial passes 0 on a turn to the right, you first want to add the dial location to the number of clicks for that turn. Then, divide that number by 100 using integer division. (That is "//" instead of "/".) To turn to the left, work in negative numbers modulo 100.

The output is the number of times we pass by 0.

BTW: if you were wondering about "0x434C49434B", that is hexadecimal code for the ASCII characters in "CLICK".

In [3]:
# Counts the number of times we reach 0
zero_count = 0

# The dial starts at 50
dial = 50

# Loop through the input
for l in lines:
    # If the line starts with "R", add the digits to the counter (modulo 100)
    if l[0] == "R":
        zero_count += (dial + int(l[1:])) // 100
        dial = (dial + int(l[1:])) % 100
    # If the line starts with "L", subtract the digits to the counter (modulo 100)
    elif l[0] == "L":
        zero_count += (((-dial) % 100) + int(l[1:])) // 100
        dial = (dial - int(l[1:])) % 100
    # If we don't have "R" or "L", something has gone wrong
    else:
        print("Incorrect input")

# Print the output
print(zero_count)
6561