diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-12-12 07:13:48 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-12-12 07:13:48 +0100 |
| commit | fad0e790ec93eb4c9f4b993041000338e2d59996 (patch) | |
| tree | 6584ed573248dea1a00049972c5c13436e9c6968 /2025 | |
| parent | 23494faa0f69b4aa0bb0e83cdbcf8657e14266d5 (diff) | |
| download | aoc-fad0e790ec93eb4c9f4b993041000338e2d59996.tar.gz aoc-fad0e790ec93eb4c9f4b993041000338e2d59996.zip | |
Diffstat (limited to '2025')
| -rw-r--r-- | 2025/12/a-if-it-was-serious.py | 45 | ||||
| -rw-r--r-- | 2025/12/a.py | 21 | ||||
| -rw-r--r-- | 2025/README.md | 15 |
3 files changed, 79 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 @@ | |||
| 1 | import fileinput | ||
| 2 | |||
| 3 | class 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 | |||
| 31 | class 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 | |||
| 40 | with 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 | |||
| 1 | import fileinput | 4 | import fileinput |
| 2 | 5 | ||
| 6 | def present_area(lines5): | ||
| 7 | return sum(l.count('#') for l in lines5) | ||
| 8 | |||
| 9 | def 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 | |||
| 15 | def fits(wh, c, areas): | ||
| 16 | return wh[0]*wh[1] >= sum(c[i] * areas[i] for i in range(6)) | ||
| 17 | |||
| 3 | with fileinput.input() as lines: | 18 | with 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 | ||
| 23 | print(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 | ``` |
| 13 | Day -Part 1- -Part 2- | 13 | Day -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 | ||
| 228 | The paths in part 1 are small enough that memoization is not required, | 229 | The paths in part 1 are small enough that memoization is not required, |
| 229 | but in part 2 we need to cache the intermediate results. | 230 | but in part 2 we need to cache the intermediate results. |
| 231 | |||
| 232 | ## Day 12: Christmas Tree Farm | ||
| 233 | |||
| 234 | This problem is literally a prank, I did not like it. I feel bad for the | ||
| 235 | people who actually try to solve it. | ||
| 236 | |||
| 237 | The actual problem of trying to fit all the presents optimally is | ||
| 238 | impossible. Maybe you can come up with an algorithm that works in theory, | ||
| 239 | but it's the kind of thing that won't finish until the starvation of | ||
| 240 | the last star in the galaxy or stuff like that. | ||
| 241 | |||
| 242 | But you can try some simple heuristics, like: if I could chop the presents | ||
| 243 | in 1x1 pieces, would they fit? Of course this condition is only necessary, | ||
| 244 | and never sufficient... unless you are being pranked. Like in this case. | ||
