aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2025-12-12 07:13:48 +0100
committerSebastiano Tronto <sebastiano@tronto.net>2025-12-12 07:13:48 +0100
commitfad0e790ec93eb4c9f4b993041000338e2d59996 (patch)
tree6584ed573248dea1a00049972c5c13436e9c6968
parent23494faa0f69b4aa0bb0e83cdbcf8657e14266d5 (diff)
downloadaoc-master.tar.gz
aoc-master.zip
Merry Christmas?HEADmaster
-rw-r--r--2025/12/a-if-it-was-serious.py45
-rw-r--r--2025/12/a.py21
-rw-r--r--2025/README.md15
-rw-r--r--README.md2
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
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))
diff --git a/2025/README.md b/2025/README.md
index 951213c..9dac728 100644
--- a/2025/README.md
+++ b/2025/README.md
@@ -11,6 +11,7 @@ Example
11 11
12``` 12```
13Day -Part 1- -Part 2- 13Day -Part 1- -Part 2-
14 12 00:58:32 00:58:36
14 11 00:14:22 00:21:19 15 11 00:14:22 00:21:19
15 10 00:27:43 11:51:51 16 10 00:27:43 11:51:51
16 9 00:05:05 02:11:41 17 9 00:05:05 02:11:41
@@ -227,3 +228,17 @@ or not we have passed through the two required intermediate nodes.
227 228
228The paths in part 1 are small enough that memoization is not required, 229The paths in part 1 are small enough that memoization is not required,
229but in part 2 we need to cache the intermediate results. 230but in part 2 we need to cache the intermediate results.
231
232## Day 12: Christmas Tree Farm
233
234This problem is literally a prank, I did not like it. I feel bad for the
235people who actually try to solve it.
236
237The actual problem of trying to fit all the presents optimally is
238impossible. Maybe you can come up with an algorithm that works in theory,
239but it's the kind of thing that won't finish until the starvation of
240the last star in the galaxy or stuff like that.
241
242But you can try some simple heuristics, like: if I could chop the presents
243in 1x1 pieces, would they fit? Of course this condition is only necessary,
244and never sufficient... unless you are being pranked. Like in this case.
diff --git a/README.md b/README.md
index f52faa9..5941383 100644
--- a/README.md
+++ b/README.md
@@ -14,4 +14,4 @@ See `year/README.md` for instructions on how to run my code.
14|2022| 50 | Rust | Done in 2025 to learn Rust | 14|2022| 50 | Rust | Done in 2025 to learn Rust |
15|2023| 50 | C | All solved by December 25, 2023 | 15|2023| 50 | C | All solved by December 25, 2023 |
16|2024| 50 | C++ | Each solved within 24h | 16|2024| 50 | C++ | Each solved within 24h |
17|2025| 22 | Python | Work in progress... | 17|2025| 24 | Python | Each solved within 12h |

Generated with cgit - Back to sebastiano.tronto.net