commit fad0e790ec93eb4c9f4b993041000338e2d59996
parent 23494faa0f69b4aa0bb0e83cdbcf8657e14266d5
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Fri, 12 Dec 2025 07:13:48 +0100
Merry Christmas?
Diffstat:
4 files changed, 80 insertions(+), 3 deletions(-)
diff --git a/2025/12/a-if-it-was-serious.py 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
@@ -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))
diff --git a/2025/README.md b/2025/README.md
@@ -11,6 +11,7 @@ Example
```
Day -Part 1- -Part 2-
+ 12 00:58:32 00:58:36
11 00:14:22 00:21:19
10 00:27:43 11:51:51
9 00:05:05 02:11:41
@@ -227,3 +228,17 @@ or not we have passed through the two required intermediate nodes.
The paths in part 1 are small enough that memoization is not required,
but in part 2 we need to cache the intermediate results.
+
+## Day 12: Christmas Tree Farm
+
+This problem is literally a prank, I did not like it. I feel bad for the
+people who actually try to solve it.
+
+The actual problem of trying to fit all the presents optimally is
+impossible. Maybe you can come up with an algorithm that works in theory,
+but it's the kind of thing that won't finish until the starvation of
+the last star in the galaxy or stuff like that.
+
+But you can try some simple heuristics, like: if I could chop the presents
+in 1x1 pieces, would they fit? Of course this condition is only necessary,
+and never sufficient... unless you are being pranked. Like in this case.
diff --git a/README.md b/README.md
@@ -14,4 +14,4 @@ See `year/README.md` for instructions on how to run my code.
|2022| 50 | Rust | Done in 2025 to learn Rust |
|2023| 50 | C | All solved by December 25, 2023 |
|2024| 50 | C++ | Each solved within 24h |
-|2025| 22 | Python | Work in progress... |
+|2025| 24 | Python | Each solved within 12h |