From fad0e790ec93eb4c9f4b993041000338e2d59996 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Fri, 12 Dec 2025 07:13:48 +0100 Subject: Merry Christmas? --- 2025/12/a-if-it-was-serious.py | 45 ++++++++++++++++++++++++++++++++++++++++++ 2025/12/a.py | 21 ++++++++++++++++++-- 2 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 2025/12/a-if-it-was-serious.py (limited to '2025/12') diff --git a/2025/12/a-if-it-was-serious.py b/2025/12/a-if-it-was-serious.py new file mode 100644 index 0000000..59ffd72 --- /dev/null +++ b/2025/12/a-if-it-was-serious.py @@ -0,0 +1,45 @@ +import fileinput + +class Present: + def __init__(self, lines5): + self.baseshape = [line[:-1] for line in lines5[1:4]] + self.area = sum(l.count('#') for l in self.baseshape) + + @staticmethod + def pretty(s): + return '\n'.join(s) + + def __str__(self): + return Present.pretty(self.baseshape) + + @staticmethod + def singlerot(s): + return [''.join(s[j][2-i] for j in range(3)) for i in range(3)] + + @staticmethod + def singleflip(s): + return [''.join(s[i][2-j] for j in range(3)) for i in range(3)] + + def shape(self, rot, flip): + s = list(self.baseshape) + for _ in range(rot): + s = Present.singlerot(s) + if flip: + s = Present.singleflip(s) + return s + +class Region: + def __init__(self, line): + wh, n = line[:-1].split(': ') + self.w, self.h = tuple(int(i) for i in wh.split('x')) + self.p = [int(i) for i in n.split(' ')] + + def __str__(self): + return f"({self.w}x{self.h}) {self.p}" + +with fileinput.input() as lines: + lines = list(lines) + presents = [Present(lines[5*i:5*(i+1)]) for i in range(6)] + regions = [Region(line) for line in lines[30:]] + +# Then you'd have to find some algorithm to solve this, but it is crazy hard diff --git a/2025/12/a.py b/2025/12/a.py index 5fdb11b..cac2c38 100644 --- a/2025/12/a.py +++ b/2025/12/a.py @@ -1,6 +1,23 @@ +# Just estimate if the shape fit basd on the area. I feel like I am +# being pranked, this problem sucks. + import fileinput +def present_area(lines5): + return sum(l.count('#') for l in lines5) + +def region(line): + wh, n = line[:-1].split(': ') + wh = tuple(int(i) for i in wh.split('x')) + c = [int(i) for i in n.split(' ')] + return wh, c + +def fits(wh, c, areas): + return wh[0]*wh[1] >= sum(c[i] * areas[i] for i in range(6)) + with fileinput.input() as lines: - for line in lines: - ... + lines = list(lines) + areas = [present_area(lines[5*i:5*(i+1)]) for i in range(6)] + regions = [region(line) for line in lines[30:]] +print(sum(1 if fits(*region, areas) else 0 for region in regions)) -- cgit v1.3