This commit is contained in:
Stefan Harmuth 2025-12-05 06:37:27 +01:00
parent 3592f06064
commit c1673d910c
3 changed files with 1253 additions and 0 deletions

55
day05.py Normal file
View File

@ -0,0 +1,55 @@
from tools.aoc import AOCDay
from typing import Any
class Day(AOCDay):
inputs = [
[
(3, "input5_test"),
(782, "input5"),
],
[
(14, "input5_test"),
(353863745078671, "input5"),
]
]
def parse_input(self) -> (list[tuple[int, int]], list[int]):
ranges, ids = self.getMultiLineInputAsArray()
return [tuple(map(int, x.split("-"))) for x in ranges], list(map(int, ids))
def part1(self) -> Any:
ranges, ids = self.parse_input()
ans = 0
for _id in ids:
for _range in ranges:
if _range[0] <= _id <= _range[1]:
ans += 1
break
return ans
def part2(self) -> Any:
ranges, _ = self.parse_input()
checked = []
for _range in ranges:
for c in checked.copy():
if (c[0] <= _range[0] <= c[1] + 1) or (c[1] >= _range[1] >= c[0]) or (_range[0] <= c[0] and _range[1] >= c[1]):
checked.remove(c)
_range = (min(_range[0], c[0]), max(_range[1], c[1]))
checked.append(_range)
ans = 0
for _range in checked:
ans += _range[1] - _range[0] + 1
return ans
if __name__ == '__main__':
day = Day(2025, 5)
day.run(verbose=True)

1187
inputs/input5 Normal file

File diff suppressed because it is too large Load Diff

11
inputs/input5_test Normal file
View File

@ -0,0 +1,11 @@
3-5
10-14
16-20
12-18
1
5
8
11
17
32