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/12/a-if-it-was-serious.py | |
| parent | 23494faa0f69b4aa0bb0e83cdbcf8657e14266d5 (diff) | |
| download | aoc-master.tar.gz aoc-master.zip | |
Diffstat (limited to '')
| -rw-r--r-- | 2025/12/a-if-it-was-serious.py | 45 |
1 files changed, 45 insertions, 0 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 | ||
