feat: add solution 2025/12
This commit is contained in:
0
data/example/2025/12.txt
Normal file
0
data/example/2025/12.txt
Normal file
65
src/solution/year_2025/day_12.py
Normal file
65
src/solution/year_2025/day_12.py
Normal file
@@ -0,0 +1,65 @@
|
||||
import functools
|
||||
from typing import Any
|
||||
|
||||
|
||||
class Shape:
|
||||
def __init__(self, shape: list[str]):
|
||||
self.shape = shape
|
||||
|
||||
@functools.cached_property
|
||||
def size(self) -> int:
|
||||
return sum(sum(x == "#" for x in s) for s in self.shape)
|
||||
|
||||
|
||||
class Grid:
|
||||
def __init__(self, a: int, b: int, amount: list[int]) -> None:
|
||||
self.a = a
|
||||
self.b = b
|
||||
self.amount = amount
|
||||
|
||||
@functools.cached_property
|
||||
def size(self) -> int:
|
||||
return self.a * self.b
|
||||
|
||||
|
||||
def _parse_input(input_data: str) -> tuple[list[Shape], list[Grid]]:
|
||||
*_shapes, _grids = input_data.split("\n\n")
|
||||
|
||||
shapes = []
|
||||
for s in _shapes:
|
||||
shapes.append(Shape(s.splitlines()[1:]))
|
||||
|
||||
grids = []
|
||||
for g in _grids.splitlines():
|
||||
size, amount = g.split(": ")
|
||||
a, b = size.split("x")
|
||||
|
||||
grids.append(Grid(int(a), int(b), list(map(int, amount.split()))))
|
||||
|
||||
return shapes, grids
|
||||
|
||||
|
||||
def part_1(input_data: str) -> Any:
|
||||
shapes, grids = _parse_input(input_data)
|
||||
|
||||
s = 0
|
||||
for g in grids:
|
||||
gifts = sum(a * b.size for a, b in zip(g.amount, shapes, strict=True))
|
||||
|
||||
# all cases are trivial xd
|
||||
if gifts <= g.size:
|
||||
s += 1
|
||||
|
||||
return s
|
||||
|
||||
|
||||
def part_2(_: str) -> Any:
|
||||
return "Marry Christmas!"
|
||||
|
||||
|
||||
def test_part_1(example_data):
|
||||
assert part_1(example_data) == 0
|
||||
|
||||
|
||||
def test_part_2(example_data):
|
||||
assert part_2(example_data) == 0
|
||||
Reference in New Issue
Block a user