StyleInCode

RSS

 

Day 11 - Advent of Code 2025

11 December 2025

Working solutions for the day 11 puzzles.

Part One

""" day_11_01.py """

# usage: python3 day_11_01.py < input

import sys


def ways(begin, end, graph):
    """ how many ways from begin to end in graph """
    if end in graph[begin]:
        return 1

    return sum((ways(i, end, graph)
                for i in graph[begin] if i != 'out'))


devices = {}
with sys.stdin as infile:
    for entry in infile:
        key, values = entry.split(': ')
        devices[key] = values.split()

print(ways('you', 'out', devices))

Part Two

""" day_11_02.py """

# usage: python3 day_11_02.py < input

import sys
from functools import cache


@cache
def ways(begin, end, graph):
    """ how many ways from begin to end in graph """
    dests = [vs for k, vs in graph if k == begin][0]

    if end in dests:
        return 1

    return sum((ways(i, end, graph)
                for i in dests if i != 'out'))


devices = []
with sys.stdin as infile:
    for entry in infile:
        key, values = entry.split(': ')
        devices.append((key, tuple(values.split())))
devices = tuple(devices)

svr_dac = ways('svr', 'dac', devices)
dac_fft = ways('dac', 'fft', devices)
fft_out = ways('fft', 'out', devices)

svr_fft = ways('svr', 'fft', devices)
fft_dac = ways('fft', 'dac', devices)
dac_out = ways('dac', 'out', devices)

total = (svr_dac * dac_fft * fft_out +
         svr_fft * fft_dac * dac_out)

print(total)

Categories

Links