StyleInCode

RSS

 

Day 1 - Advent of Code 2025

1 December 2025

Working solutions for the day 1 puzzles.

Part One

""" day_01_01.py """

# usage: python3 day_01_01.py < input

import sys


def step(instruction):
    """ calculate displacement """
    if instruction[0].lower() == 'r':
        return int(instruction[1:])
    return -int(instruction[1:])


count = 0
dial = 50

with sys.stdin as infile:
    for rotation in infile:
        dial = (dial + step(rotation)) % 100

        if dial == 0:
            count += 1

print(count)

Part Two

""" day_01_02.py """

# usage: python3 day_01_02.py < input

import sys


def step(instruction):
    """ calculate spins and displacement """
    loops, disp = divmod(int(instruction[1:]), 100)
    if instruction[0].lower() == 'r':
        return loops, disp, 1
    return loops, disp, -1


count = 0
dial = 50

with sys.stdin as infile:
    for rotation in infile:
        spins, distance, delta = step(rotation)
        count += spins

        for _ in range(distance):
            dial += delta
            dial = dial % 100

            if dial == 0:
                count += 1

print(count)

Categories

Links