Day 2 - Advent of Code 2026

Working solutions for the day 2 puzzles.

Part One

""" day_02_01.py """

# usage: python3 day_02_01.py < input

import sys


def wyps():
    """ yield the next waypoint """
    wps = ['r', 'o', 'y', 'g', 'b', 'v']
    while True:
        yield from wps


waypoint = wyps()

total = 0

with sys.stdin as infile:
    next(waypoint)
    while (op := infile.read(1)) and op != '\n':
        while next(waypoint) != op:
            total += 1
        total += 1

print(total)

Part Two

""" day_02_02.py """

# usage: python3 day_02_02.py < input

import sys


tally = {}

with sys.stdin as infile:
    while (op := infile.read(1)) and op != '\n':
        tally[op] = tally.get(op, 0) + 1

wps = ['r', 'v', 'b', 'g', 'y', 'o']

total = 0

carry = 6
for wp in wps:
    if tally.get(wp, 0) == 0:
        carry -= 1
    else:
        total += carry + (tally[wp] - 1) * 6
        carry = 5

print(total)