#!/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())