aboutsummaryrefslogtreecommitdiff
path: root/2025/12
diff options
context:
space:
mode:
Diffstat (limited to '2025/12')
-rw-r--r--2025/12/a-if-it-was-serious.py45
-rw-r--r--2025/12/a.py21
2 files changed, 64 insertions, 2 deletions
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 @@
1import fileinput
2
3class Present:
4 def __init__(self, lines5):
5 self.baseshape = [line[:-1] for line in lines5[1:4]]
6 self.area = sum(l.count('#') for l in self.baseshape)
7
8 @staticmethod
9 def pretty(s):
10 return '\n'.join(s)
11
12 def __str__(self):
13 return Present.pretty(self.baseshape)
14
15 @staticmethod
16 def singlerot(s):
17 return [''.join(s[j][2-i] for j in range(3)) for i in range(3)]
18
19 @staticmethod
20 def singleflip(s):
21 return [''.join(s[i][2-j] for j in range(3)) for i in range(3)]
22
23 def shape(self, rot, flip):
24 s = list(self.baseshape)
25 for _ in range(rot):
26 s = Present.singlerot(s)
27 if flip:
28 s = Present.singleflip(s)
29 return s
30
31class Region:
32 def __init__(self, line):
33 wh, n = line[:-1].split(': ')
34 self.w, self.h = tuple(int(i) for i in wh.split('x'))
35 self.p = [int(i) for i in n.split(' ')]
36
37 def __str__(self):
38 return f"({self.w}x{self.h}) {self.p}"
39
40with fileinput.input() as lines:
41 lines = list(lines)
42 presents = [Present(lines[5*i:5*(i+1)]) for i in range(6)]
43 regions = [Region(line) for line in lines[30:]]
44
45# 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 @@
1# Just estimate if the shape fit basd on the area. I feel like I am
2# being pranked, this problem sucks.
3
1import fileinput 4import fileinput
2 5
6def present_area(lines5):
7 return sum(l.count('#') for l in lines5)
8
9def region(line):
10 wh, n = line[:-1].split(': ')
11 wh = tuple(int(i) for i in wh.split('x'))
12 c = [int(i) for i in n.split(' ')]
13 return wh, c
14
15def fits(wh, c, areas):
16 return wh[0]*wh[1] >= sum(c[i] * areas[i] for i in range(6))
17
3with fileinput.input() as lines: 18with fileinput.input() as lines:
4 for line in lines: 19 lines = list(lines)
5 ... 20 areas = [present_area(lines[5*i:5*(i+1)]) for i in range(6)]
21 regions = [region(line) for line in lines[30:]]
6 22
23print(sum(1 if fits(*region, areas) else 0 for region in regions))

Generated with cgit - Back to sebastiano.tronto.net