Compare commits

..

5 Commits

Author SHA1 Message Date
Tobias Radloff
e064a666fa Day 10 Part 2 (finally working) 2025-12-16 00:03:34 +01:00
Tobias Radloff
02da337a77 Day 10 Part 2 (works w/o errors but takes ages and result is wrong) 2025-12-15 12:57:14 +01:00
Tobias Radloff
f342df95c5 Day 12 2025-12-14 00:11:19 +01:00
Tobias Radloff
321d55e31c Day 11 2025-12-11 22:34:25 +01:00
Tobias Radloff
cd47c076a4 Day 10 Part 1 2025-12-11 09:14:10 +01:00
6 changed files with 2205 additions and 0 deletions

153
day10.py Normal file
View File

@ -0,0 +1,153 @@
#!/usr/bin/env python
# https://adventofcode.com/2025/day/10
from itertools import combinations
from pulp import LpProblem, LpMinimize, LpVariable, LpInteger, LpStatus
from pulp import lpDot, lpSum, value
# imports for function part2()
from itertools import product
from sympy import symbols, Matrix, solve_linear_system
f = open("day10input.txt", "r")
# regular input
input = f.readlines()
# testinput
#input = "[.##.] (3) (1,3) (2) (2,3) (0,2) (0,1) {3,5,4,7}\n[...#.] (0,2,3,4) (2,3) (0,4) (0,1,2) (1,2,3,4) {7,5,12,7,2}\n[.###.#] (0,1,2,3,4) (0,3,4) (0,1,2,4,5) (1,2) {10,11,11,5,10,5}".split("\n")
# prep data
machines = []
for input_line in input:
line = input_line.rstrip("\n").split(" ")
machine = {}
# final state
fs = line[0][1:-1].replace(".", "0").replace("#", "1")
machine["fs"] = int(fs, base=2)
# switches
switches = []
for switch in line[1:-1]:
s = ["0"] * len(fs)
for i in [int(j) for j in switch[1:-1].split(",")]:
s[i] = "1"
switches.append("".join(s))
machine["s"] = sorted([int(s, base=2) for s in switches], key=int.bit_count)
# joltage req's
machine["j"] = [int(n) for n in line[-1][1:-1].split(",")]
machines.append(machine)
def print_machines(machines: list[dict]) -> None:
for i in range(len(machines)):
print(f"Machine no. {i}")
for k in machines[i].keys():
print(f"key:\t{k}\tvalue:\t{machines[i][k]}")
def part1_bfs(m):
for steps in range(1, len(m["s"])):
# check if current step no yields a solution
for c in list(combinations(m["s"], steps)):
lights = 0
for i in c:
lights ^= i
if lights == m["fs"]:
print(f"Success with combo {i} and step count of {steps}")
return steps
return None
# my own attempt to solve each problem with sympy
# problem is that sympy computes not a minimum but a general solution
# So for each problem I have to back-substitute possible combinations for the free variables and find the minimum with brute force
# the function works, runs a long time, and the final solution is off by 1 :-/
def part2(m):
switches = [list(map(int, list("{0:b}".format(switch).zfill(len(m["j"]))))) for switch in m["s"]]
joltages = m["j"]
# define sympy symbols and equations
x = symbols(f"x:{len(switches)}", integer=True)
system = Matrix([[switch[j] for switch in switches] + [joltages[j]] for j in range(len(joltages))])
print(f"Equation system to solve: {system}")
# solve system with sympy
solutions = solve_linear_system(system, *x)
print(f"Solutions: {solutions}")
# isolate free variables
free_vars = [var for var in x if var not in solutions.keys()]
print(f"{free_vars=}")
# find smallest solution
smallest_sum = None
# loop over the cartesian product of sensible numbers for button presses times the number of free variables
for lv in product(range(max(joltages)), repeat=len(free_vars)):
current_sum = sum(lv)
for v in solutions.values():
for i in range(len(lv)):
v = v.subs(free_vars[i], lv[i])
if v < 0:
current_sum = -1
break
current_sum += v
if current_sum < 0:
continue
# check current sum
if not current_sum.is_Integer:
continue
elif not smallest_sum or current_sum < smallest_sum:
smallest_sum = current_sum
print(f"Smallest number of presses found: {smallest_sum}")
return smallest_sum
# Second attempt: solving each problem with pulp, a Python library for linear programming
# runs blazingly fast, returns correct solution
def part2_pulp(m):
switches = [list(map(int, list("{0:b}".format(switch).zfill(len(m["j"]))))) for switch in m["s"]]
joltages = m["j"]
# define problem via pulp
problem = LpProblem("Advent of Code 2025, Day 10, Part 2", LpMinimize)
# define variables
x = LpVariable.matrix("x", list(range(len(switches))), 0, None, LpInteger)
# add objective function to problem
problem += lpSum(x)
# add equations to problem
for j in range(len(joltages)):
problem += lpDot(x, [switch[j] for switch in switches]) == joltages[j], f"Equation {j}"
problem.solve()
# the minimum number of steps necessary to reach the desired joltages is the sum of all variables
return sum([value(xi) for xi in x])
#print_machines(machines)
# solve part 1
print(sum(list(map(part1_bfs, machines))))
# solve part 2
steps = 0
for machine in machines:
# solve the machine using sympy and back-substitution
# steps += part2(machine)
# solve the machine using pulp
steps += part2_pulp(machine)
print(f"current total step number: {steps}")
print(f"final total step number: {steps}")

200
day10input.txt Normal file
View File

@ -0,0 +1,200 @@
[..#.##.##] (0,1,2,3,4,5,8) (2,3,5,7) (2,5,6,7) (0,3,4,5,6,7,8) (0,2,4,6,7,8) (0,1,2,4,5,8) (0,2,4,5,6) (0,1,3,4,7,8) (0,1) (2,3,6) {55,25,58,54,55,53,44,43,42}
[##..#..] (0,3) (0,1,2,5,6) (0,1,2,4,5) (1,3,4,6) (1,2,3,4,5) (1,6) (1,2,4,5) (0,5) (3,4,5,6) {151,96,61,49,74,197,61}
[.##..#.] (4,5) (0,1,3,6) (0,1,2,3,5,6) (1,2,5) (0,1,4,6) (0,1,2,5,6) {31,42,19,20,8,21,31}
[#...###] (1,4,6) (0,2,4,5,6) (0,1,2,3,5,6) (2,3,5) (1,4,5) {11,18,26,16,27,27,27}
[##...###] (0,1,3,4,5,6,7) (1,2,3,5,6,7) (0,5) (0,2,3,5,7) (2,3,4,5,7) (1,3,4,5,6) (0,1,3,4,6) (1,5,6) (3,5) {158,192,24,194,174,81,192,35}
[.#.##...#] (1,2) (1,3,7,8) (1,2,5,7) (4,7) (1,2,4,5,6,7) (0,1,2,3,5,6,8) (0,3,4,5,6,7,8) {22,156,139,39,6,134,25,132,39}
[.#..] (0,1,2) (0,3) (1,2) (3) (0,2) {47,24,44,16}
[#...#] (1,2,3,4) (0,2) (0,1,2,3) {4,2,6,2,2}
[..#.] (1,3) (0,3) (0,2,3) {33,7,14,40}
[.#.#..##.#] (0,4,5,6) (2,7) (4,5) (0,1,2,3,4,5,6,7) (0,1,2,3,5,6,7,8) (1,3,8) (1,3,5,9) (0) (0,2,3,4,6,8) (0,8) (4,5,6,8) (0,1,4,5,6,7,8,9) (0,2,3,4,5,6,7,9) {82,38,35,35,52,58,60,39,51,9}
[##.##] (0,2,3) (1,2) (1,2,3) (0,1,4) {22,22,36,36,4}
[#####....] (0,1,2,4,5,7) (6) (4,5) (0,1,2,5,6,7,8) (0,3,5,6,7,8) (0,1) (0,2,5,8) (0,1,2,3,4,6,8) (8) (1,3,4,6) (1,4,8) {163,146,35,26,33,46,40,33,39}
[..#.##...] (1,2,6,7,8) (1,2,5,6,7,8) (0,1) (0,1,3,4,5,8) (1,3,4,5,7) (2,3,4,6,7,8) (3,4,5) (0,3,6,8) {17,36,16,23,21,34,18,21,22}
[..#.] (0,2) (1,2) (0,2,3) (0,3) (0,1) (0) {26,9,14,12}
[.#.#] (1,3) (0,2,3) {13,16,13,29}
[#....#.##.] (3,8) (2) (1,2,5,6,8) (0,1,3,4,5,6,8) (1,2) (0,3) (0,5,9) (7,8) (1,4,9) (0,1,3,4,5,7,8,9) (4,6,7,8) (1,5) {26,36,20,20,29,32,28,23,34,18}
[#.####] (0,1,2,4) (1,2,3) (0,1,3) (1,3) (0,4) (5) (3,4,5) (1,5) {32,58,12,42,25,24}
[..#.##..##] (0,3,4,7,8) (0,1,3,4,5,6,8,9) (2,3,4) (6,9) (0,1,2,4,5,6,9) (0,5,7,8,9) (4,5,8) (4) {39,29,29,34,84,46,31,10,39,31}
[.#..#..] (1,4,5) (3,5,6) (2,5) (0,2,3,4,6) (1,3,4,5,6) (0,4) (0,1,4,5,6) {22,40,8,28,45,64,45}
[#...] (0) (0,1) (0,2) (0,3) (2) {39,14,23,5}
[.##..#] (0,1,4) (0,1,4,5) (1,2,5) (0,2,5) (1,2,4,5) (0,1,2,3,5) (2,3) {53,63,51,31,34,49}
[.#...] (1,2,3,4) (3) (0,3,4) (1) (0,2) (1,3) (3,4) {23,149,16,50,18}
[.#..#] (0,1,2) (0,2,3,4) (1,3) (2,3) (1,4) {10,31,17,15,22}
[##########] (0,2,5,6,7) (2,5,6,7,9) (0,3,4,5,6,8) (1,4) (1,6,8) (2,3,4,5,6,7) (0,1,2,3,4,6) (0,1,3,4,8) (1,4,5,6,7,8,9) (2,4,5,6,8) {42,49,54,54,87,55,77,27,57,11}
[.#.#.#.] (2,4) (0,5) (1,2,5,6) (0,1,3) (0,1,4,5,6) {22,25,13,3,23,25,22}
[.####..#] (3,5,6) (1,5,7) (0,3,4,7) (0,1,3,6) (0,2,4,6,7) (0,4) (0,1,3,5) {57,33,15,43,35,35,31,38}
[.##.#] (1,2,4) (0,1,3) (1,2) {7,35,28,7,9}
[####.] (0,1,2,3) (0,3,4) (0,2,3) (0,1,2) (2,3,4) {126,20,132,133,8}
[###..#...#] (3,6,7) (1,2,6) (0,2,3,4,5,6,9) (1) (0,1,2,5,6,7) (0,1,2,3,6,7,8,9) (0,1,2,3,5,6,8,9) (1,2,3,4,5,6,8,9) (0,5,6,8,9) (1,2,4,7,9) (0,3,8,9) (0,2,4,5,6,7,8) (2,3,5,6,8,9) {56,74,68,51,33,39,58,48,52,69}
[.#..##.##.] (1,3,5,7,8,9) (1,3,4,5,6,7,8,9) (3,8) (0,1,4,5,7) (1,3,6,8,9) (0,2,3,4,6,7,8,9) (4,7,8) (1,5) (0,1,2,3,4,5,6,8) (4,6,7,8) {27,60,19,56,49,44,47,39,74,29}
[......##] (0,1,2,7) (0,1,2,3,4,5,7) (0,1,3,4,6,7) (1,2,3,5,6) (0,2,3,6) (1,4,6,7) {47,50,46,60,35,26,56,36}
[..##.#..] (0,1,2) (0,4) (2,3,5,7) (0,2,3,4,5,6) (0,1,3,4,6,7) (0,1,3,6,7) (5,6,7) (0,4,5,6,7) (0,2,3) {253,33,46,51,226,48,55,50}
[.#.#] (0,1,2) (1,3) {0,7,0,7}
[#...#...#] (6) (5,7) (0,1,3,4,6,7,8) (0,2,3,6,7,8) (0,1,5,8) (2,7) (0,1,4,8) (4,5,6) (0,4,5,6,7,8) {44,16,26,15,27,45,48,59,44}
[#..##..] (0,1,2,4,5,6) (3,4,5) (0,1,3,4,5,6) (1,4,5) (2) (0,1,3,4,5) (1) (2,3,5) (0,1,4,5,6) {44,54,30,20,55,57,40}
[..###...##] (0,2,5,6,8) (0,1,2,3,4,5,8,9) (2,3,4,5,7) (0,3,4,5,6,8,9) (2,7,9) (0,1,2,3,4,5,7,8,9) (1,7) (1,2,3,4,5,6,7,8,9) {30,37,48,54,54,59,39,57,44,48}
[..##.###] (0,1,2,3,4,5) (1,2,3,4,5) (0,4,5,7) (0,1,4,5,6,7) (0,2,4,5,7) (0,1,5,6) (1,4) (2,3,4,5,7) (0,3,5) {58,53,56,58,72,83,10,29}
[..###...] (1,2) (0,1,3,4,5,7) (3,4,5) (1,3,4) (0,6) (0,1,2,3,6) {10,39,20,29,23,4,10,0}
[.#....##] (2,3,5) (1,2,3,4,6) (1,3,7) (1,2,3,4,6,7) (4,5) (0,4,6,7) {15,29,25,36,47,21,33,26}
[...#..] (0,1,2,4) (1,5) (0,2,5) (1,3) (0) (2,4,5) (0,2) (0,1,4,5) {168,183,164,18,158,39}
[...#.....] (0,2,4,5,6,7,8) (1,5,7,8) (0,1,6) (1,2,3,7,8) (0,4,5,6,7,8) (0,3,5,6,7,8) (1,2,6,7,8) (0,1,3,6,7,8) (1,2,3,4,5,6,7) (2,4) (0,1,2,7) {81,77,60,51,37,50,76,94,74}
[###..#..#.] (2,9) (0,2,4,6,7,9) (3,4,5,6,7,9) (0,2,3,6,7,8,9) (0,1,3,5,6,8,9) (0,1,4,5,6,7,8) (0,4,6) (3,8) (0,3,4,5,6,8,9) (0,1,2,5,6,8,9) (3,7) (0,1,2,5,6,9) {125,72,82,167,78,94,144,79,176,120}
[#.#####.] (0,1,3,5,7) (1,5,7) (2,4,6) (0,1,3,4,7) (1,3,5) (0,4,5) (0,1,2,4,6) (1,2,4,5,7) (1,2,3) (3,5,6) {48,69,36,41,57,59,20,47}
[#.#.#] (0,2,4) (1,2,4) (0,1,2) (1,3) {169,37,181,18,174}
[..##..##] (1,2) (1,3) (0,4,5,6) (5,6) (1,3,6,7) (1,2,3,4,6,7) (1,2,3,7) (1,4,5,6) (0,2,3,5) {27,67,44,56,34,45,54,33}
[###.....] (0,1,5,7) (0,2) (0,2,4,5,6,7) (3,4,6,7) (0,1,2,4,5,6,7) (1,7) {48,27,36,0,21,33,21,39}
[#....##] (1,2,4,5,6) (1,2,6) (0,2,3,5) (2,3,4,5,6) (0,2,4,5,6) (0,2,6) (0,1,3,5) (4,5) {35,43,65,13,36,46,63}
[.########] (3,4,5,6,7,8) (0,1,2,3,4,5,6) (0,2,5,6,8) (1,2,3,4,5,6,8) (1,3,4,5,6,7,8) (0,3,5,6,7,8) (0,2,3,4,6,8) (0,1,2,4,5,6,7) (2,3,5,6) (0,1,7) {38,39,37,69,69,58,75,49,56}
[##..#.] (2,3,4,5) (0,1,3,5) (1,5) (0,3,4) (2,4) {13,18,27,26,30,31}
[#...##.] (2,3) (1,4,6) (0,1,2,3,4,5,6) (1,5) (3,6) (3,5) {4,25,9,28,16,20,28}
[#####] (2,4) (0,3,4) (0,4) (2,3) (1,2,3) {16,0,24,29,24}
[.#.#.#] (1,2,5) (0,2,4,5) (0,1,2,3,4) (1,3,4) (0,4) {19,39,25,27,38,17}
[#......] (0,3,4,5,6) (1,5) (0,1,3) (0,2,3,6) (0,1,2,4,6) (1,2,3,4,5) {39,36,47,36,38,21,37}
[.##.####] (0,6) (0,5) (3,7) (0,1,3,4,6,7) (2,4,6) (1,2,3,5,7) (4,6,7) (1,4,5,6) {28,36,9,21,53,23,60,37}
[.###...] (3,4,5,6) (0,2,3,4,6) (0,2,3,6) (1,2,3,5) (2,4,6) (3,5,6) (0,4,5,6) (1,5) (1) {41,52,59,71,61,84,93}
[#..#..#.#.] (0,1,3,4,5,6,8,9) (0,3,6,8) (0,1,2,5) (4,5) (0,5) (1,2,3,6,7,9) (0,1,3,8) (1,3,9) {62,40,16,46,21,47,40,10,36,28}
[.#.###] (0,1,2,3) (1,3,5) (1,2,3,5) (2,5) (4) (0,1,2,3,5) (0,2,4,5) {28,26,48,26,19,48}
[#.##] (0,1,2) (0,2,3) (1) (2,3) {10,8,23,20}
[###..#.] (0,2,5) (0,1,2,6) (0,2,4,5,6) (0,3) (2,3,4,5,6) (1) (2,4) (2,4,6) {65,27,76,18,43,37,48}
[###..##] (0,1,2,6) (2,6) (1,3,6) (2,3,6) (2,3) (4,5) (0,1,4,6) {34,44,50,28,38,18,76}
[.##.#] (1,4) (1,2,4) (0,3,4) {2,14,4,2,16}
[###.] (0,1,2) (0,1,3) {115,115,12,103}
[..#.] (0,3) (2) (1,3) {17,16,9,33}
[....#.#] (0,3,5) (6) (1,2,4) (4,5,6) (1,2,4,5,6) (3,4,6) (0,2,3,4) (1,2,3,5,6) (4) {24,14,30,204,228,39,221}
[#..##] (2,4) (0,2) (0,1,2) (0,1,3,4) (2,3) (1,3) {30,27,176,172,18}
[#..#.#.] (0,1,2,4,5) (1,2,3,4) (0,1,3,5,6) (1,2,4,5,6) (3) {39,68,49,49,49,50,30}
[#.###.] (3,4,5) (2,4,5) (2,4) (0,2) (1,2) (0,3,4) (0,1) (0,3) {147,40,55,135,51,23}
[..##] (0,1) (0,2) (1,2,3) (1,3) (0,1,2) {206,195,38,6}
[#.#.##...#] (1,3,8,9) (3,5,6,7,8) (1,3,5,8,9) (0,2,8,9) (0,3,5,6,8) (1,3,4,5,7,8,9) (0,1,2,6,7,9) (0,2,3,4,5,6,7,9) (1,2,5,9) (0,1,4,5,6,7,8,9) (0,4,5,9) (2,6,7,8,9) {74,58,74,56,30,87,80,64,80,110}
[..#.] (1,2,3) (2,3) (2) (1) (0,2) {15,7,37,4}
[##..##] (1,2,3,4) (2,3,4) (0,2,5) (1,3) (2,3) {12,23,215,210,189,12}
[.####..#.#] (1,2,3,6) (0,2,3,4,5,6,8,9) (5,7,9) (1,2,3,5,6,7,8) (3,4,7) (0,1,2,3,4,5,7,8,9) (1,9) (1,3,6,8) (1,2,3,4,5,6,8,9) (0,6,7,8,9) (1,3,4,5,6,7) {23,69,48,69,45,68,64,52,57,56}
[..##] (2,3) (1) (0,2) (1,3) (1,2) {16,25,38,16}
[#.#....] (0,1,3,4,5) (1,2,3,5) (3,4,6) (1,2,4,5) (3,5,6) (0,3,5,6) (1,2,4,5,6) (0,1,2,5) {14,60,52,61,52,80,44}
[#..#..##.] (0,1,2,3,4,7) (1,2,3,4,5,6,7,8) (1,4) (2,4,5,6,7) (0,1,2,3,4,5,7,8) (0,2,3,5,6,7) (0,3) (2,3) (0,4,5,7) (3,5,6) {57,52,69,89,72,64,35,67,27}
[#.#.##] (3) (4,5) (1,2) (0,3) (4) (0,1,3,5) {15,12,10,176,20,8}
[....##] (3,4) (0,1,2,5) (0,3,4) (0,2) (0,1,2,3) (4,5) (1,2,5) {27,32,40,23,16,25}
[..#.###.##] (2,4,5,7,8) (0,6,9) (0,1,3,5,6,8,9) (0,2,4,5,6,7,8,9) (2,3,6,7,8) (0,1,2,3,4,5,6,7,8) (0,4,5,6,7,9) (2,3,4,5,7,8,9) (0,1,8,9) {78,34,37,32,54,67,69,57,62,76}
[#..##] (2,3) (1,4) (0,3,4) {5,13,16,21,18}
[####] (0,1,2,3) (0,2,3) {29,15,29,29}
[...#....##] (2,3,4,9) (3,5,9) (0,1,2,3,4) (2,3,5,6,7,8,9) (7,8) (3,4,9) (0,1,3,5,6) (0,1,2,6,9) (4,8) (8) (0,1,4,6) (1,2,3,4,8) (0,1,2,4,5,6,7) {74,74,68,60,69,42,68,31,27,51}
[##.###..##] (2,4,8) (5,6,7,8) (2,6,8) (0,4,6,7,8,9) (3,5,7) (0,2,3,4,5,6,8) (1,6) (1,2,3,4) (2,3,4) {9,20,52,44,39,24,38,15,32,0}
[.##...] (0,3,5) (1,2) (0,2) (0,4,5) (0,4) (0) (5) (1,2,3,5) {37,28,28,18,18,33}
[..#...#] (0,1,3,5) (0,2,5,6) (0,1,3) (4,5,6) (0,1,3,4,5,6) (2,6) (0,1,2,4,5) (0,4,5) {81,50,37,30,60,81,39}
[...######.] (0,3,4,5,6,7,8) (1,4,5,6) (1,2,3,6,7,8,9) (0,1,5,7,9) (9) (2,6) (4,5,8,9) (1,2,3,5,6,7,8,9) (0,1,2,4,5,6,7) (0,3,5,7) (0,2,3,5,6,8,9) (0,1,4) {69,48,28,33,49,67,44,46,31,55}
[###...##..] (2,6) (0,2,3,4,5,6,7,8,9) (0,1,2,5,6) (0,1,2,3,4,7,8,9) (0,1,4,5,6,9) (3,5) (0,2,9) (0,1,2,4,6,7) (6,9) (0,1,8,9) (0,1,2,3,4,5,8) {287,74,298,75,76,77,83,57,55,243}
[#....##.#] (1,3,5,8) (0,5,7) (0,2,7,8) (0,1,2,3,4,5,6,7) (5,7) (5,6,8) (1,7,8) (0,2,3,4,5,7,8) (0,3,4,5) (0,2,5,6) (0,6,7,8) {97,42,58,58,42,113,72,92,88}
[.#.##.#.#.] (2,6) (0,2,3,4,5,8,9) (0,1,3,5,6,7,8,9) (0,1,2,3,4,5,7,9) (2,9) (0,3,6,7,8) (1,2,3,5,7,8,9) (1,4) (0,1,3,4,5,6,7,8) (5,7,9) {61,61,46,71,58,59,52,61,62,42}
[###.###.] (0,3,5,6) (0,3,5,7) (1) (1,3,4,6) (0,1,4) (0,2,3,5,6,7) (3,4,7) (2,3,4,5,6) {177,24,153,190,33,178,180,152}
[#######.] (1,2,4,7) (1,2,3,5,6,7) (0,1,2,5,7) (2,3,6) (0,1,2,3,4,5,6) (0,1,2,5,6) {36,54,65,40,13,53,44,38}
[.#.#] (0,1,2) (1,3) {102,122,102,20}
[.####.] (3,4) (1,2) (0,3,4) (1,4,5) {2,33,13,109,129,20}
[...##..##] (0,1,2,3,5,6,7) (0,1,4,6) (0,1,5,8) (3,7,8) (1,2,3,4,5,6,7) (0,3,7,8) (0,1,2,4,6,7,8) (1,2,4,5,6,7,8) {52,189,182,51,167,168,187,198,165}
[.##..#..] (0,1) (1,2,3,6) (2,3,4,6,7) (1,2,6,7) (0,1,2,4,5,7) (0,4,7) (2,5,6,7) (2,3) {21,39,56,45,19,7,30,23}
[#.###] (1,2) (0,2,3,4) (0,1,2,3) (0,2,3) {166,30,177,166,141}
[#.##] (2,3) (0,1) (1,2,3) (0,2) {18,34,19,18}
[#.###.##.] (0,2,3,4,5,8) (1,2) (4,6) (0,3,4,6,7,8) (2,4,8) (0,3,5,7,8) (0,3,4,5,6,7,8) (0,6,7) (1,5,8) (0,1,2,4,5,8) (5,6) {45,16,203,26,216,51,33,29,229}
[.##.....##] (0,2,3,4,5,6,8,9) (0,1,2,5,6,7,8) (0,1,7) (6,7) (0,1,2,3,4,5,7,8,9) (3,4,8,9) (8,9) (0,1,2,3,4,5,7,8) (0,1,2,3,5,6,7) (2,4,9) (5,6,9) (0,1,2,5,6,7,9) {64,45,69,71,65,67,54,46,72,81}
[.#..] (0,2) (1,3) (0,1) (1) (0) (1,2) {26,182,5,14}
[#.##] (0,1) (0,1,2) (3) (0,2,3) (1,3) {36,44,22,52}
[##....] (1,4,5) (0,1,3,5) (1,2,4) (0,2,4) {16,33,9,15,19,25}
[#.##.##.#] (0,6) (3,8) (2,6,7) (0,1,2,4,6,7) (0,1,4,5,6,8) (0,1,2,3,4,7,8) (0,3,5,6,7) (0,3,6,8) (0,1,2,4,5,6,7) (0,6,7) (0,1,4,6,7) {68,52,47,45,52,18,67,61,50}
[##...] (0,3,4) (0,1) (2,3) (0,1,2,4) (0) {30,10,27,23,14}
[##.....#] (0,2,3,4,5) (1,2,6) (3,4,6,7) (0,1,7) (3,6,7) (0,1,2,3,4,5,7) (1,2,3,5) {132,43,133,170,134,132,39,64}
[##.#] (0,1,3) (0,1,2) {160,160,12,148}
[.#######] (0,1,3,6) (1,2,3,4,5,6,7) (0,1,3,5) (2,4,5) (0,1,2,4,6,7) (0,2,3,5,6,7) (0,1,2,3,4,6,7) (0,6,7) (1,6) (0,1,4,6) {92,83,64,61,62,37,111,75}
[#...] (0,1,3) (3) (1) (0,1,2) (0) (2) {22,21,5,25}
[.##.##] (2,3) (0,2,3,4) (0,1,3,5) (0,1,2,4) {28,8,34,40,21,7}
[##.#.#.#] (2,3,4,5,6,7) (0) (0,1,2,3,7) (0,1,4,7) (3,4,6,7) (1,4) (2,4,5,6,7) (2,6,7) {28,31,58,41,84,36,75,91}
[.#....] (2,4,5) (0,3) (0,1,2,4) (0,1) (0,2) (0,1,2,3,4) {239,31,31,216,23,6}
[#...###] (3,4,6) (1,2,4) (4,5,6) (0,2,3,5) (0,2,3,5,6) (0,4,5) (1,2,3,4,5) (1,2,3,4,6) {26,16,39,44,47,50,35}
[....##..] (0,3,4,5) (0,1,4,7) (2,6) (0,2,3,4,5,6,7) (1,2,3,4,7) (0,3,4,5,6,7) {22,21,37,31,37,16,22,27}
[##.##] (3,4) (2,3,4) (0,1,2,3) (0,1,3,4) (0,3) (0,2,4) (0,2) {65,17,46,56,52}
[.....#..#.] (0,1,2,4,6,7,8) (1,3,4,7) (2,4,9) (0,2,4,5,8,9) (0,4,5,7) (0,3,7,8,9) (0,1,2,3,6,8,9) (1,4,5,7,8) (1) (0,1,2,3,4,6,7,9) (6) {44,58,40,46,72,29,16,65,54,54}
[#.#.] (1,2) (0,3) (0,2) (0) (0,1,2) (2) {40,24,43,4}
[###...#..#] (2,5) (1,5,6,7) (1,2,4,6,8) (2,7,8) (1,6) (0,2,3,4,5,6,8,9) (1,7,8) (4,6,7,9) (1,3,4,7,8,9) (0,1,2,3,6,7,9) (0,6) (0,3,4,6,7,9) (1,3,5,6,7,8,9) {51,78,53,62,53,28,91,71,49,62}
[.#...#.] (0,1,4,5) (5) (0,1,2,3,6) (1,2,3,4,6) (0,6) (0,1,4) {177,180,29,29,168,17,43}
[...###.] (0,1) (3,4,5,6) (0,1,3,4,5,6) (1) (5,6) (2,4) (0,2,4) (0,1,3,4,5) (2,3,5) {40,38,33,68,71,76,47}
[#.###] (0,3) (0,2,3,4) (0,1,2,3,4) {35,9,20,35,20}
[#.#.#...#] (0,1,2,4,5,6,7) (5,6) (1,3,4,6) (0,1,2,5,6) (2,3,6,7,8) (0,1,2,3,4,5) (0,1,6,8) (0,2,4,6,7,8) (0,2,7) {68,57,78,37,47,42,91,59,34}
[###...#.##] (0,1,2,3,6,7,8,9) (4,6) (2,4,5,6,7,8,9) (0,1,4,5,6,7,8,9) (0,1,2,8,9) (0,2,4,5,6,7,8,9) (3,8) (1,5) (0,1,2,3,5,7,8,9) (1,7) (1,2,3,4,6,7,9) {203,209,52,45,202,212,222,222,238,220}
[..##...##.] (1,2,3,4,5,6,8,9) (2,3,7,8) (2,5,7) (1,2,3,4,5,6,7,9) (0,1,8,9) (0,1,2,4,8,9) (1,4,8) (0,2,6,8,9) (1,5,9) {26,59,48,21,40,40,20,30,29,57}
[.#.#..#...] (1,2,3,4,6,7,8,9) (0,2,4,6,9) (4,6,9) (0,1,2,5,6,7,8,9) (0,2,3,6,8) (0,7) (2,5,6,7) (0,1,5,6,7,8,9) (2,3,5,7,9) (1,2,6) (0,1,2,4,5,6,7,8) (4,6) {78,39,88,28,43,53,107,63,56,56}
[..#.#.] (2,4) (2,3,5) (1,4,5) (0,3,4,5) (0,1,3,5) (0,1,2,4) {35,33,41,34,55,47}
[...#...###] (1,3,6,8) (0,2,3,5,7,9) (0,1,6,7,8,9) (1,2,3,6,8,9) (0,1,3,7,9) (3,7,8,9) (0,2,3,4,7,8,9) (1,4,6,8) (1,6,9) {43,71,34,75,24,16,66,59,80,79}
[##.##] (0,1,2) (0,1,3,4) (1,4) {22,38,14,8,24}
[..#..#.] (0,1,2,3,4) (0,1,3,4,5) (1,4,5,6) (1,4) (0,1,2,5,6) {30,44,11,29,43,32,13}
[.#.#] (0,1,2,3) (1,3) (2,3) {17,28,21,32}
[#.#.] (0,2) (1,2,3) {4,10,14,10}
[..##.#] (0,3) (0,1,2,4) (2,3,5) (1,2,4,5) {12,4,14,22,4,14}
[##...#....] (1,3,4,6,7,8) (6,9) (0,1,2,3,4,6,9) (2,4) (0,1,2,3,6,7,8) (0,1,2,3,4,5,6,8) (0,3,4,6,8,9) (0,1,2,3,4,5,7) (5,6,7) (1,3,4,5,6,8,9) (0,3,6) {54,37,35,58,41,25,73,35,36,34}
[.#######] (1,3,6,7) (1,4,5) (0,3,4,6,7) (0,6,7) (1,3) (2,3,5,7) (2,4) {30,39,16,51,42,13,41,44}
[##....##.#] (6,8) (1,3,4,5,6,7) (1,2,3,4,5,6,7,8) (1,2,4,5,7,9) (0,1,2,5,6,7,9) (0,2,3,4,5,6,8,9) (0,1,5,6,7,8) (1,2,3,4) (2,9) (0,1,3,4,5,6) (0,2,5,6,7) (0,1,4,6,7,8,9) (1,2,3,8,9) {86,110,111,69,82,117,119,93,75,74}
[.#......#.] (1,7,8) (1,2,3,4,6,8) (1,2,3,4,5,7,8) (1,5,9) (2,3,4,5,6,7,8,9) (1,8,9) (0,1,2,3,4,5,6,9) (3,5,6,7) (0,3,5,6,9) (1,2,3,6,9) {31,61,64,81,53,60,74,25,42,66}
[#..#...] (1,3,4,5,6) (0,3,4,6) (2,6) (2,4) (1,4,6) (1,2) (2,3,4,5) {14,21,37,38,57,24,50}
[#####..] (0,1,2,3,4) (3,5) (4,6) (0,6) (2) (0,1,4,5) {26,23,38,20,144,7,124}
[#.#...##] (1,2,4,6) (0,1,2,4,5,6,7) (0,2,3,6) (1,4,6,7) (0,3,4,6,7) (1,5) (3,6) {41,58,39,46,59,31,87,43}
[##.#...#.] (0,6) (0,1,3,7) (1,5) (1,2,3,5) (0,1,2,5,6,8) (0,1,2,3,5,7) (0,1,2,4,6) {220,226,27,210,5,25,17,203,8}
[.#.##] (1,3,4) (0,3) (0,2) (0) (1,3) (0,1) (0,1,3) {49,32,20,37,10}
[#####...] (0,1,2,3,4,6,7) (0,1,2,7) (2,3,4) (4,5,7) (0,1,2,3,5,6) (0,1,4,5,7) {46,46,56,50,43,29,30,29}
[.###...#] (1,2,4,7) (0,2,4,6,7) (2,3,6) (5,6) (1,2,3,4,5,6) (3,6) (4,7) {10,17,41,33,34,16,55,30}
[.#.###...] (5,6,7) (1,4,7) (1,3,7,8) (0,2,5,6) (4,5) (0,1,2,4,7,8) (0,1,2,3,4,5,7) (1,2,4,5,7) {39,72,49,33,65,48,12,83,31}
[..#.#] (0,2,3) (0,1,2) (1,2) (0,3,4) {40,28,45,21,4}
[.#.#...] (1,2,3,5,6) (0,1,2,6) (0,2,3,5) (2,3) (0,1,2,3,5) (2,3,4,6) (0,1,2,4,5) (0,1,3,4,5,6) (1,3,4,6) {193,220,227,96,192,196,81}
[.#...] (0,1,2,3) (2,4) (1,2,4) {3,18,23,3,20}
[#.#...###] (0,6) (1,4,8) (0,4,5,6) (1,2,4,6,7) (5,6) (0,1,5,6,7,8) (2,3,4,5,6,7,8) (0,2,7,8) (0) (3) (1,5) {61,60,35,30,48,71,80,53,57}
[#.##.##.] (7) (0,3,4,5,6,7) (0,3,4) (2,5) (1,3) (0,3,6,7) (0,1,4,5,6) (1,2,3,6,7) (2,3) {44,30,32,61,34,31,52,41}
[####..####] (2,4,5,7,8) (0,4,5,6,8) (1,4,5,6,7,8,9) (0,1,4,5,6,7,8,9) (1,3,4,5,7,9) (0,1,2,3,4,5,9) (3,7) (0,1,2,3,6,9) {37,48,37,39,55,55,42,58,45,48}
[..#.##...] (4,5) (0,2,7) (0,2,3,5,6,7,8) (0,1,4,7) (2,3,7,8) (0,1,2,3,4,6) (0,1,2,3,5,6,7,8) (1,3,6,7) (3,5) {41,34,53,59,17,38,40,75,38}
[..##..] (1,5) (0,5) (2,4,5) (0,2,4,5) (1,2,3) (0) {27,19,166,1,165,184}
[##..] (0,3) (0,2,3) (0,1,2) (1,3) {24,32,23,26}
[##.##] (3,4) (0,4) (0,2,3) (1,3) {29,1,15,24,22}
[#....#.##] (0,1,3,6,8) (0,6,8) (1,5,7) (0,1,2,3,4,5,6,8) (1,2,3,4) (5,7) (0,2,3,4,5,6) (1,3,5,6) {46,42,27,36,27,53,51,26,44}
[##...#.#] (1,2,6,7) (0,1,3,4,5,7) (0,2,3,4,6,7) (1,2,3) (1,5,6,7) (3,7) (1,2,3,4) (0,1,4,5,6,7) {37,53,47,55,54,25,51,66}
[....#.#.#] (2,3,5,8) (0,1,2,5,7) (0,5,7,8) (1,7) (0,2,3,5,6) (0,3,6,7) (0,1,4,6,7) (1,2,3,4,6,7,8) {24,31,32,32,11,36,18,46,38}
[.####.] (2,4,5) (0,1,2,4) (1,3,5) (0,4) (1) (1,4,5) (1,2) (2,3,5) {7,142,137,25,30,48}
[#.#####] (3,6) (0,2,3) (0,1,3,4,5,6) (0,1,2,3,4,6) (0,4) {227,17,191,220,36,17,29}
[###..#] (1,4) (0,3) (0,1,4) (1,2,3,5) (1) (3,4,5) (0,1,4,5) (1,2,4,5) {38,79,31,53,72,56}
[#.#.#] (0,1,3,4) (0,1,2) (0,4) (3,4) (0,2,3,4) (0,3,4) (0,2,4) {49,22,18,18,42}
[...#..] (3) (0,4) (5) (0,1,4) (2,5) (1,4,5) (0,2,4) (3,4,5) {29,29,106,31,59,153}
[#.#.###.] (0,2,6) (0,1,5,7) (3,6,7) (6,7) (0,1,2,4,5,6) (0,1,3,6,7) (5) (5,6,7) (3,4) {38,29,12,49,20,25,62,63}
[.##.#.] (0,1,3,5) (0,1,3,4,5) (0,1,2,4,5) (0,1,2,3) (3,4) (4) (1,5) (0,3,4) {183,185,150,191,49,41}
[#...###.] (0,1,2,3,4) (0,1,2,3,4,6) (0) (2,5) (3,4,5,6,7) (0,1) (0,1,3,4,5,6,7) (0,1,4,5,6,7) (1,4,6) (1,2,3,4,6,7) {46,55,22,31,55,44,51,31}
[.###..#.#] (0,2,3,4,7,8) (2,3,6) (0,2,5,6,7,8) (1,2,4,7,8) (1,5) (0,3,5) (1,8) {24,33,36,31,17,23,19,23,40}
[..#.##..] (0,1,3,5,6) (4,6) (0,2,6) (2,5,7) (1,2,4,7) (1,2,3,4,5,7) {23,216,215,209,203,217,26,208}
[.#.#..] (2,3,4) (3,4) (0,5) (1,3) (0,2) {10,0,18,24,24,4}
[###.#.####] (0,5,8,9) (1,5,6,7,8) (1,6) (5,7) (1,2,4,6,8) (0,2,3,4,7) (2,3,4,5,7) (0,2,3,4,7,8,9) (0,1,2,3,4,6,7,8) {28,23,20,13,20,46,23,42,45,25}
[..##..] (0,5) (1,2,3,4,5) (3,4,5) (1,2,4,5) (1,3,4,5) (0,1,4,5) (0,1,2,3,4) {35,46,35,29,52,61}
[.....##] (0,1,4,5,6) (0,1,2,5,6) (5,6) (0,1,3,4,5) (0,1,2,3,6) (0,1,5) (1,2,3,5,6) (4,6) (2,3) {73,93,76,58,36,83,98}
[..#####..] (0,1,2,5,7,8) (0,4,6,7,8) (1,3,4,5,6) (2,5,7) (0,3,5,6,7) (1,5,8) (1,3) {37,220,10,226,217,220,229,42,26}
[####.#] (0,1,2,4,5) (2,3) (0,1,5) (0,4) {198,198,195,9,186,198}
[..#..#.] (3,4) (0,2) (0,3,5,6) (0,2,3) (0,1,2,3,4,6) (1,2,4,6) (0,2,5) {44,17,47,39,35,4,18}
[.###..##.] (0,1,2,3,5) (0,7) (0,1,2,3,5,6,8) (0,1,4,6) (1,5,8) (3,4,6,8) (1,2,3,5,6,7,8) (1,2,5) (0,2,3,5,6,8) (5,7) (0,1,2,3,4,6,8) {90,92,78,180,125,103,177,50,178}
[.#.##.] (2,3,4) (0,3,4) (0,1,2,3) (0,1,2,4,5) (2,3) {24,13,36,46,25,1}
[####...#.#] (0,1,7,8) (5,9) (2,7,8) (4,6,7,8) (0,1,4,6,9) (0,1,2,3,5,6,7,9) (3,6) (5,8) (0,1,2,3,6,8,9) (0,1,2) (0,1,2,3,5,7,8,9) {33,33,45,32,5,30,27,37,48,38}
[#....] (0,1,2) (1,2,3) (0,1,4) (0,2,4) {28,39,37,16,12}
[##..#] (1,3,4) (0,1) (1) (0,4) (1,2) (3,4) {17,29,9,25,41}
[.##.##.##] (1,3,6) (0,1,2,3,4,5,6) (1,3,4,8) (1,6) (0,1,2,5,7) (0,1,2,7,8) (0,1,2,5,6,7,8) (0,4,8) (1,8) {45,59,25,25,45,22,29,20,57}
[.###..] (0,1,2,3) (0,4) (1,2) (0,5) (0) (1,2,3,4) (1,2,3,5) (1,2,3) {48,42,42,27,36,18}
[......##] (0,1,2,3,4,6,7) (2,7) (0,4,5,6,7) (2,3,4,5,6,7) (1,2,3,6,7) (3,4,5,7) (1,5,7) (1,3,4,5,6,7) {19,28,32,45,42,36,42,65}
[...#.##..#] (2,4,5,7,9) (0,2,3,5,6,8) (7,9) (2,6,8,9) (0,1,3,5,6,7,9) (0,2,7,8) (0,1,3) (4,6) (3,6,7) (0,2,3,5,6,7,9) (1,2,6,8,9) {84,36,69,71,167,45,230,67,48,53}
[##.###.##] (0,3,4,5,7,8) (0,3,4,5) (3,7) (1,3,5) (0,2,5,6,8) (1,4,7,8) (0,1,4,7,8) (2,6,7,8) {52,31,24,37,41,48,24,36,47}
[##.#] (1,2) (0,1,3) (0,2,3) {205,19,186,205}
[#....] (0,3) (0,1,4) (0,3,4) (1,2) (0,2,3) (4) (1,3) {27,21,13,39,13}
[##..#.#..] (4,5,6) (0,3,4,5,6,7,8) (1,3,4,5,6,7,8) (0,1,2,3,5,6,7) (1,2,6,8) (0,3,4,5,6,8) (2,4,5,6,7) (0,1,2,4,5,7) (1,2,3,4,6,7) (1,6,8) {184,214,195,205,69,219,244,211,62}
[.###....] (2,3,4,5,6) (1,3,4) (0,1,6) (0,5,7) (1,2,4,5,6,7) (1,2,4,5,6) (3,4,5,6) {27,50,34,25,51,54,63,18}
[..##..] (1) (0,2,3,4) (0,1,2,3,4) (1,2) (2,3,5) (0,3,4,5) {45,29,52,60,45,25}
[.#...] (0,1,3) (0,1,4) (1,2) (2,4) (3,4) (0,1,3,4) {141,155,15,14,148}
[##..] (3) (0,1) (0,2) (0,1,3) (1,3) (0,3) {58,32,17,46}
[##.###.] (0,4,5) (0,1,4,5,6) (0,2,5,6) (0,1,2,3) (1,2,3,4,6) (0,2,3) {45,29,39,25,16,25,28}
[#####] (1,2,4) (0,1,3) (0,1) (0,4) (1,2,3) (4) {41,62,31,36,27}
[#.##] (1,2,3) (0,1,2) (1,3) (0,3) (2) {22,22,27,34}
[..#.#] (1,3,4) (0,2,3,4) (0,2) (0,1,4) (2,4) {30,21,25,32,39}
[#..#.] (1,4) (0,3) (1,2,4) {6,25,19,6,25}
[.#..] (0,2,3) (2,3) (1,2) (0,3) {11,6,12,11}
[##..#...] (0,1,4) (3,6) (0,1,2,5) (0,2,4,6,7) (1,2,3,4,5,7) (3,6,7) (2,3,5,6,7) (2,5,7) (4) (1,3,4,7) {31,32,156,40,37,138,39,160}
[##...] (1,2,3) (0) (3) (2) (2,4) (0,3) (0,1,3) {14,22,42,38,11}
[#.#....] (0,2) (0,1,6) (2,3,4,5,6) (0,2,4,6) (4) (0,2,3,6) (0,1,2,4,6) (1,4,5,6) (1,2) {56,44,58,12,55,17,60}
[###.##.] (0,1,3,5,6) (0,2,4,5,6) (0,1,2,4,5,6) (1,3) (2,4) (0,1,2,3,4,6) (0,1,2,4,5) {33,24,43,17,43,26,26}
[..#..#..#] (1,2,3,4,5,8) (0,2,3,5,6,7) (0,1,3,4,5,6,7,8) (0,1,5,6,8) (2,4,6,7) (1,2,3,8) (0,1,3,5,6,7) (0,2,4,5,6,7) (5,6,8) (1,2,5) {54,61,54,49,14,72,60,40,38}

95
day11.py Normal file
View File

@ -0,0 +1,95 @@
#!/usr/bin/env python
# https://adventofcode.com/2025/day/11
f = open("day11input.txt", "r")
#f = open("testinput.txt", "r")
graph = {}
for line in f.readlines():
node, outputs = line.strip("\n").split(":")
graph[node] = outputs.strip().split(" ")
def part1(current_path: list[str] | str, end: str) -> None:
if isinstance(current_path, str):
current_path = [current_path]
node = current_path[-1]
# check for dead ends
if node not in graph.keys():
return
# check if end node is reachable from current node
if end in graph[node]:
found_paths.append(current_path + [end])
return
# check all outputs
for output in graph[node]:
# avoid loops
if output in current_path:
continue
part1(current_path + [output], end)
def part2(start: str, end: str) -> int:
print(f"STARTING BACKWARDS SEARCH FROM {end} TO {start}")
num_paths = {end: 0}
def backsearch(target_node: str, current_node: str) -> int:
# init num_paths value for current node
num_paths[current_node] = 0
# find nodes with edges into current node
inputs = list(filter(lambda n: current_node in graph[n], graph.keys()))
# check if current_node is a dead end
if len(inputs) == 0:
return
# loop over input nodes
for node in inputs:
# check if node is the target node
if node == target_node:
num_paths[current_node] = 1
# input node was visited already
elif node in num_paths.keys():
num_paths[current_node] += num_paths[node]
# input node was not yet visited
else:
backsearch(target_node, node)
num_paths[current_node] += num_paths[node]
return
backsearch(start, end)
return num_paths[end]
# part 1
found_paths = []
part1("you", "out")
print(len(found_paths))
# part2
svr2dac = part2("svr", "dac")
print(svr2dac)
dac2fft = part2("dac", "fft")
print(dac2fft)
fft2out = part2("fft", "out")
print(fft2out)
svr2fft = part2("svr", "fft")
print(svr2fft)
fft2dac = part2("fft", "dac")
print(fft2dac)
dac2out = part2("dac", "out")
print(dac2out)
print("final result:", svr2dac * dac2fft * fft2out + svr2fft * fft2dac * dac2out)

647
day11input.txt Normal file
View File

@ -0,0 +1,647 @@
dfa: nbz qhk kzw
nzm: ors
coh: hvt mrm yvu
grm: jon
jcu: dco reg
hgd: zum ets rml
yqr: gbd you dev oki
zia: fft gpd
wgs: mwd
rma: smb
pfh: jgr
kva: wkb elg
ggl: qcf hvt
egb: hzs dwx
nwk: out
owz: nwk abc
loe: adu roz vis
qdw: npt you dev
esy: pbj gyu nph jeh
fdg: ykn epk jau
piz: dxz jbc swk
bby: pxp
qcf: enj qhf sav siy tbn ccn
req: ckp lew
you: vhr jzm onn muy wsz pba nqx chd uvn fgl leo tvv ajb
epk: gbd npt dev oki
ttu: hzs dwx weu dsm
ajb: knu
zis: owr wie sdo
baz: icr xxa
wof: hht wwo hpk
yde: aha acu gob
ugq: bpa
gxo: muw gcw dca kja
cnf: swk
kby: spx suh ats
qgt: php zqq jva pkm
oeh: huq ahv gun van
osl: qcf hvt yvu
hya: gob szv aha ors acu
vlc: lfr vfm xsh
hqt: ptd nid
ifl: yvu qcf
nba: ddz hsk are wkt
gob: xsh vfm lfr
ckc: zia tub
biu: qrc
ekm: wgs mit
oki: jcu nqx mok uvn pph pfh ajb tvv vhr onn avk jzm vcb muy pba qvl chd ssk leo dnj nno fgl wqz vyw wsz
ytg: isi thh csk
fwt: xzk guu obh
ivc: xog
pkm: xxa icr
wux: qcf yvu hvt mrm
yjo: spx
zqq: xxa ptd icr
scc: xsh
jbc: bby grt
ssk: ugq rhm
epo: bgi avt vrq
hmi: awf
uhe: xog ble
dla: yaa shj
hok: ryk anu qqm mag zes uhe ygh kaj jif syl dla qdf nle vao udl dvq xil
ors: lfr dhl xsh
vrt: xsh lfr
onn: wfl
xhi: smb
wol: nqc fga frw
mfc: wyu hhq
uku: obh xzk wcz
vyw: ekm
tmh: mrm
lfr: lvh dly ibi yee ywp ksa ogz rog zph fks nnp qnp zsg drv
vhh: dhl
rhb: jur cgb
ovf: dln bvr
azm: vzw yfz osl bmb
ken: vso ybh ifl ofa
for: scc icp
fuj: nmg zia dls
scb: ijp ekw
lme: mod ygu
cev: til yox axf
fks: red qip sda
szv: vfm dhl xsh
ygf: vnf xvj hgd
ygu: icr ptd xxa
zzz: qbf kik
weh: out
ljf: xvj ybc
php: ptd nid
wsx: rgq
wnb: snh wct
suh: vfm
are: ilu
qec: yuj lwk tso
uys: vip
guu: out
nkj: loi jfl ejf
ddw: asd yot owz
tid: bgi qzw xiv
dmu: kgk gxo ebz yaa
ptd: der inq jwg piz klp qag mtj yyf emp foa fgy ift zii lwe ddd gbz
qhv: dfd tnj vkj
nmv: mwb vkj dfd
isi: uba izt mdn xhi
jau: npt gbd oki
bhg: vas rnl ora pnt
mcg: otw mfq
wkr: dev oki npt gbd
vis: oih
kzw: jur
wwo: ivg acz
ykn: you oki dev
oen: hvt
dsu: ytg cim
kzx: byq few btc rrz
mrm: qgx tbn dsu kbc ccn rci crh neh wnb enj sav xur mfc azx qgu qiq qhf apg siy
ucs: ead rhb
swk: grt bby
nvu: hvt qcf
jon: vhh vlc
few: out
vgb: lfr dhl xsh
gdd: hvt yvu
osi: jvm zmz ddw
thh: izt rma uba
dys: wbu ucs bpf
vso: hvt mrm qcf
npt: wqz fgl nno dnj leo ssk chd wsz vyw tvv ajb pfh pph uvn mok jcu nqx biu qvl pba muy vcb jzm avk onn vhr
dac: epk kbw jau
izj: mea hmi
qrc: jxk epv
vaf: qgt
ddd: bhg bcj
pph: jgr rhm ugq
nfh: qmt csk thh
qdf: hyp
ets: out
xgk: dhl xsh
boa: hpk hht
ppr: wof
ble: lht ugz bpr
dyg: qmt
dca: cpe eyi
hjm: nep yya kik
zes: hyp uzy
vgl: hfm
vkp: mgv iah
vsh: cts xtl xsp
rrz: out
ckp: hsk ddz kqe
mxe: yuj
tre: luh
paz: wwo
luh: wcg
bvv: vxi etm
qzw: fri
hht: vgl yjo acz kby
itk: sdc alv tjv
xyo: hpz axf yox yyn
xkh: hhq zdi wyu qix
kgk: muw
mit: fsf mvk mwd
qse: lqt lxh wil
ofa: hvt mrm yvu qcf
ior: icr ptd nid xxa
syz: duo
vrq: rxb pfk fri
snh: hyg nop vaf sgh
csk: uba rma izt mdn xhi
dpw: jur zod
xwy: lsk bbi
mvk: tlo itk juq
wbu: rhb
otw: loi tcv
gpd: vrt scc
xog: ugz lht bpr bvv
nbr: byq few
hzt: wsx fms
sda: tdh bye eif ggl
byq: out
gbd: uvn pph mok jcu nqx ajb tvv pfh onn avk jzm vhr pba qvl biu vcb muy chd ssk wqz leo nno dnj vyw wsz
rhj: paz
kaj: dfa zzp jky ost
zsg: rwo sqf xyg
reg: hoi epv
oee: bne
jha: gyu jeh
chd: wfl
yyf: poh zzz hjm
wil: ahz
dfd: oki you gbd npt
mfj: bgi vrq xiv
fri: vyd
qvl: jgr
oyd: vfm lfr dhl
smg: oki dev you gbd
bco: amy kzx
ats: dhl vfm
cqs: lfr
tzw: oen gnu qxh gdd
rwc: mrp jbc
iwx: qlz bss awf
dnj: reg qrc dco
ibi: vrm elg
dly: ykj qip sda
jur: izj hfj tid epo ckc gwu eei syz tlb
ast: php jva zqq uxg
rnl: ngy eiq
zzp: kzw hed lfk qhk
nkp: tnj vkj
viz: mvk
hpz: ptd
qip: eif bye
rwo: pth
mwb: gbd npt
qiq: vsh vca
prl: kzw lfk qhk
flo: dhl lfr
lkz: hhx
siy: sce
xtl: xlz guz
kgu: qtw ura wkr smg bwf
uun: out
gyu: ldh ttu
nep: mfq gvg
bpr: qec etm mxe
ltr: gbd npt oki dev
svr: yxc gwm hok
avk: sdn zpz vvt zhw
xyg: krb wcg
boh: nmv qhv nkp
rgo: jdt rhb ead
jva: xxa nid
tni: nmg tub zia dls
nei: vfm
izd: mvp kgx scb sjc
qpy: rwo sqf
qtw: dev oki
izt: lrw baz smb
jdt: zod cgb jur
ewt: iwx mea auv
lwe: bcj
qag: sjc
hgv: osi bws hhx
sce: sdo
cts: guz hqt
vzw: hvt mrm qcf
lrw: nid icr xxa
ivg: fzd suh spx
gun: tzw eia
ebz: muw kja
abc: out
apg: lkf vsh sif
xlz: xxa nid ptd icr
see: bmi
sdn: bsl rob
cai: van huq
lrg: qtw bwf wkr smg
vsy: gfb weh uun
acu: vfm xsh
bwf: gbd npt you dev oki
sdo: nid ptd xxa
mfp: qip
dls: gpd fft
nsc: ivf
vhr: mxw dco
ldh: dpw hzs weu
vwg: paz
yfz: hvt
rci: nfh dyg nqt
bbi: qcf mrm yvu
xkj: weh
juq: tjv alv sdc
kqe: gik clq ilu
jxk: bco
inq: zzz hjm poh
nqx: ekm aet uyh
blj: ior mod rgi
udl: jha var esy vqa zex
mok: vvt sdn
fsf: juq tlo hgf
qwi: mwb dfd
ora: ngy eiq
sav: zis mbp
axf: nid ptd
kik: otw
cxl: azm
nbz: jur
zmz: vkp okc owz
zum: out
eei: boa paz
nhm: uun gfb
shj: gcw
sow: lsk
byv: ybh ofa
anu: isj xog
tso: zod jur cgb
xdr: osl vzw
jky: hed kzw qhk nbz
klc: xdr fol
vas: eiq gys
ykj: bye tdh
dsm: zod jur cgb
van: tzw azs fkq
rux: bby grt mgw
nnp: vrm wkb elg
klp: kgx scb
pth: coh jpj nvu wmz tmh
ekw: fga frw
xsh: fks mfp vlq kva kqb gtw drv qnp
hyp: fvp nba lew
hde: bvv bpr ugz
weu: jur
nmg: gpd
yvu: crh ruf rci ccn xkh kbc dsu qgx tbn sav enj wnb neh azx mfc xur siy apg qhf qiq qgu
nno: zpz zhw vvt
gwu: dln bvr
vlq: sqf rwo
lxh: ahz lme blj
bcj: vas
kgx: ggc ekw wol
tus: pkm php jva zqq
fft: icp ymx vrt vgb scc
ahv: eia azs tzw fkq
hgf: esi tjv
dhl: tre ibi fks lvh qpy cai kqb oeh ywp
vcb: reg qrc dco mxw
yuj: jur cgb
emp: mvp
nbj: obh wcz eot
muw: mao cpe eyi ybf
nvy: vso ifl ybh
yvt: ljf llb eoc
auv: dxq qlz awf
jns: ucs
smb: ptd
icp: lfr vfm dhl
lvh: vrm
wct: hyg nop vaf
foa: fms
gik: jur zod
ugz: etm
hhq: dog xzr bne xyo
qdc: eoc
pnt: gys ngy
hed: zod
acz: fzd
lqt: lme ahz
ujd: qwi
xiy: vso ybh ifl
qlz: oyd nei cqs
ssl: yvu
jeh: egb ttu ldh
wkw: vlc
ubb: guz hqt
dev: onn wsz vcb biu mok ssk uvn chd fgl nno dnj leo
vca: xsp xtl cdb ubb
uvn: zpz zhw vvt
zph: zok yvz
pyk: vhh
hsk: clq gik
kja: ybf cpe mao
jgr: wkf bjz bpa yvt
der: nkp
kbw: dev you
fkq: gdd qxh gnu
ijq: sgh vaf
dgy: uxg jva
bss: wfz flo oyd
avt: fri pfk grm rxb
bne: axf
yya: nkj
xur: sce mbp
mxw: hoi epv
qhd: lxh
eot: out
rml: out
huq: fkq azs tzw
ost: hed kzw qhk nbz
fgy: scb
jif: xog isj hde
azx: dyg cim nfh ytg
wqz: wfl loe
uxg: nid xxa
zok: lsk bbi
fbt: uun gfb
xiv: hsb
icr: pyl inq cnf boh hzt gbz klp piz aoz pkd
qbf: nkj otw mfq
qmt: uba
rgq: gys
bpf: jdt
llb: vnf ybc
vvt: bsl
gys: you oki gbd npt
yyn: ptd nid xxa
adu: oih
owr: nid icr ptd xxa
xil: hde ble
ybc: rml ets zum
cdb: xlz hqt guz
rva: guu obh wcz
yvz: wux
mkh: fwt nbj
gtd: xgk vlc
vkj: oki dev gbd
qhf: zis
fka: adu uys vis
til: ptd icr xxa
pkd: bhg wsx bcj
jzm: aet ekm
jbt: req
knu: hhx bws
syl: zex esy var jha
clq: cgb
qix: xyo xzr cev
yee: xwy sow zok
zdi: dog
ddz: gik clq
qhk: cgb jur
tbn: qhd qys qse
vfm: qpy fks zph ogz nnp oeh qnp gtw drv lvh ibi dly ywp yee cai
bjz: eoc ljf llb
xpa: njk nbr hcw
lus: eia
dln: hya
uba: lrw
iah: out
mfq: ltr ejf
ura: dev you npt
ygh: zzp dfa prl ost
sif: xtl xsp cts cdb ubb
nid: der jwg pyl inq klp piz izd pkd boh hzt emp mtj qag fgy see foa rwc lwe aoz ift gbz ddd
fga: yqr qdw caw uud
ift: qhv nkp
dfi: gfb weh
ogz: sow zok xwy yvz
pfk: wkw pyk jon gtd
alv: out
leo: fka
fzd: xsh lfr vfm
uyh: wgs viz mit
vxi: tso lwk
wkf: ygf eoc ljf
ywp: lus
loi: you oki dev
bsl: mkh jmw
qys: lxh
xzr: yyn hpz axf yox
spx: xsh
mbp: owr wie
wkt: gik
qgu: ijq
rhm: bjz wkf qdc
gvg: ltr tcv jfl loi
obh: out
bpa: llb ygf
oih: nhm dfi vsy
ymx: vfm lfr xsh
lsk: yvu
nqt: isi qmt
hcw: few rrz btc
wcz: out
sqf: wcg pth krb
ruf: wct ijq snh
tdh: qcf hvt yvu
rob: mkh ivf
wcg: jpj nvu wmz coh
fvp: ddz kqe are
eoc: xvj
sdc: out
saq: fol
lkf: xsp xtl cts ubb
muy: aet ekm
ijp: fga
grt: lrg
poh: qbf kik mcg
nph: ttu
ryk: zex
qnp: cxl
zii: swk mrp jbc rux
jvm: asd owz
etm: lwk tso yuj
hoi: bco xpa kqt
duo: yde nzm
bmi: epk
azs: gdd qxh
zod: tni hfj rhj ewt pma dbc syz fuj gwu epo vwg
dxq: oyd nei cqs flo wfz
lcw: kbw epk jau
gcw: cpe
hpk: yjo kby vgl ivg
nqc: qdw uud yqr
mdn: lrw smb baz
hhx: jvm zmz
sxj: out
hvt: dsu qiq nvm apg ruf
dwx: jur zod
pba: hgv lkz
tnj: npt gbd dev oki you
esa: yya mcg
jmw: uku nud nbj
isj: bvv lht
ybf: jur
eyi: jur cgb zod
hyg: scl tus
wmz: yvu qcf
bye: qcf yvu mrm
red: ggl eif tdh ssl
ggc: nqc
fym: gxo shj kgk ebz
mgv: out
tlo: esi tjv
lwk: zod
aoz: zzz hjm esa poh
gwm: anu ryk dmu qqm uhe zes dys jif kaj jbt qdf dla jns dvq fym vao ivc udl
gtw: vrm wkb
sgh: tus dgy
ilu: zod jur cgb
dbc: iwx hmi
ybz: lxh wil
xvj: zum
hfj: zia
krb: nvu
vqa: pbj nph
yaa: muw kja dca gcw
elg: ken byv
btc: out
hsb: gtd vyd pyk
scl: jva
jwg: bmi fdg lcw dac
bvr: yde hya
cgb: fuj vwg ban tlb eei dbc syz ovf pma hfj ndm ckc gwu tid epo mfj ewt izj ppr rhj tni
hzs: cgb
rxb: vyd wkw jon gtd
awf: nei wfz flo
ahz: rgi mod ygu
kqt: hcw amy njk
cim: csk thh
vnf: ets
bmb: qcf
nvm: ybz qhd
mtj: dac lcw bmi
caw: npt
njk: btc rrz few byq
mea: qlz
rgi: icr
ejf: you gbd npt
ivf: rva uku nbj
lfk: zod jur cgb
bnb: nhm fbt
mwd: juq hgf
vip: xkj vsy nhm
pxp: qtw bwf ura wkr smg
mrp: bby mgw
qgx: hhq oee qix
wfz: xsh
ybh: hvt mrm
tjv: out
kbc: sif vca vsh lkf
eia: gnu gdd
xxa: jwg ujd pyl inq boh piz izd pkd fgy foa emp yyf mtj qag gbz ddd aoz ift zii
gnu: qcf mrm
aha: vfm xsh
pbj: ldh ttu
neh: oee wyu qix hhq
fms: rnl
gbz: poh zzz
wkb: nvy ken byv xiy
tcv: gbd npt oki dev you
uud: you oki dev npt gbd
asd: nwk abc
pma: tub
nop: scl dgy qgt ast
ead: zod
utv: owz yot okc asd
tub: fft gpd for
esi: out
nud: eot
roz: vip bnb
bgi: grm fri
nle: zex vqa
eiq: dev you
jpj: hvt qcf
yot: abc iah mgv
zex: jeh gyu pbj
ndm: dln duo
zhw: pka
wyu: xzr
qqm: req hyp uzy
epv: kqt
dco: epv
qxh: qcf hvt mrm yvu
tlb: wof paz boa
dvq: jha zex esy
wie: ptd
yox: icr
ksa: van gun ahv huq
skr: mrm hvt
mao: cgb
ban: auv mea hmi
frw: uud qdw
vao: prl zzp dfa
zpz: rob bsl nsc pka
vyd: xgk
eif: mrm yvu qcf
cpe: zod jur
aet: viz
enj: snh
dxz: mgw
mvp: ekw wol ggc
var: nph gyu
mgw: lrg pxp kgu
lht: vxi qec etm
mag: ucs wbu rgo
pyl: nkp qwi nmv
drv: klc cxl saq
mod: nid icr xxa
amy: rrz byq
dog: yox
wfl: vis uys
bws: utv jvm
wsz: ekm uyh
tvv: wfl
yxc: ryk dmu anu qqm uhe mag jbt jif qdf jns ivc fym dvq nle xil
hfm: vfm lfr dhl
crh: qse qys
kqb: cxl saq
okc: sxj iah mgv abc
fol: skr yfz osl
xsp: xlz guz
sjc: ekw ijp
pka: mkh ivf jmw
rog: zok xwy yvz
guz: xxa ptd icr
ngy: dev oki you npt gbd
xzk: out
gfb: out
fgl: lkz knu hgv
vrm: nvy xiy
jfl: gbd npt oki you
ccn: qse
lew: ddz
uzy: lew ckp nba

80
day12.py Normal file
View File

@ -0,0 +1,80 @@
#!/usr/bin/env python
# https://adventofcode.com/2025/day/12
import re
def prep_data(filename):
shape_re = re.compile(r"\d:")
region_re = re.compile(r"\d+x\d+:")
shapes, regions, quantities = {}, [], []
f = open(filename, "r")
lines = [l.rstrip("\n") for l in f.readlines()]
f.close()
while lines != []:
line = lines.pop(0)
# shape
if shape_re.match(line):
tmp = []
# read shape lines
while True:
l = lines.pop(0)
if l == "":
break
else:
tmp.append(l)
# parse shape
shape = []
for i in range(len(tmp)):
for j in range(len(tmp[0])):
if tmp[i][j] == "#":
shape.append((i, j))
shapes["shape-" + line[:-1]] = shape
# region & quantities
elif region_re.match(line):
tmp = line.split(" ")
regions.append(list(map(int, tmp.pop(0)[:-1].split("x"))))
quantities.append(list(map(int, tmp)))
return shapes, regions, quantities
def solve_part_1() -> int:
shapes, regions, quantities = prep_data("day12input.txt")
areas = [len(shape) for shape in shapes]
solvable, unsolvable, dont_know = 0, 0, 0
# loop over problems
for i in range(len(regions)):
board = regions[i]
quantity = quantities[i]
# simple solvability check
if board[0] * board[1] < sum(list(map(lambda a, q: a * q, areas, quantity))):
print(f"Problem {i} is unsolvable")
unsolvable += 1
# check if a tileset of 3x3 squares would fit in theory
elif (board[0] // 3) * (board[1] // 3) >= sum(quantity):
print(f"Problem {i} is solvable")
solvable += 1
else:
print(f"don't know about problem {i}")
dont_know += 1
print(f"{solvable=}")
print(f"{unsolvable=}")
print(f"{dont_know=}")
return solvable
# solve part 1
print(solve_part_1())

1030
day12input.txt Normal file

File diff suppressed because it is too large Load Diff