generated from public/aoc_template
44 lines
1.0 KiB
Python
44 lines
1.0 KiB
Python
from tools.aoc import AOCDay
|
|
from tools.types import Range
|
|
from typing import Any
|
|
|
|
|
|
class Day(AOCDay):
|
|
inputs = [
|
|
[
|
|
(3, "input5_test"),
|
|
(782, "input5"),
|
|
],
|
|
[
|
|
(14, "input5_test"),
|
|
(353863745078671, "input5"),
|
|
]
|
|
]
|
|
|
|
def parse_input(self) -> (list[Range], list[int]):
|
|
ranges, ids = self.getMultiLineInputAsArray()
|
|
checked = []
|
|
for _range in [Range(*map(int, x.split('-'))) for x in ranges]:
|
|
for c in checked.copy():
|
|
if _range.overlaps(c):
|
|
checked.remove(c)
|
|
_range = _range.merge(c)
|
|
|
|
checked.append(_range)
|
|
|
|
return checked, list(map(int, ids))
|
|
|
|
|
|
def part1(self) -> Any:
|
|
ranges, ids = self.parse_input()
|
|
return sum(x in y for y in ranges for x in ids)
|
|
|
|
def part2(self) -> Any:
|
|
ranges, _ = self.parse_input()
|
|
return sum(len(x) for x in ranges)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
day = Day(2025, 5)
|
|
day.run(verbose=True)
|