34 lines
913 B
Python
34 lines
913 B
Python
from tools.aoc import AOCDay
|
|
from typing import Any
|
|
|
|
|
|
class Day(AOCDay):
|
|
inputs = [
|
|
[
|
|
(2, "input4_test"),
|
|
(538, "input4_dennis"),
|
|
(528, "input4"),
|
|
],
|
|
[
|
|
(4, "input4_test"),
|
|
(792, "input4_dennis"),
|
|
(881, "input4"),
|
|
]
|
|
]
|
|
|
|
def get_sections(self) -> (list, list):
|
|
for line in self.getInput():
|
|
s1, s2 = line.split(",")
|
|
yield list(sorted(map(int, s1.split("-")))), list(sorted(map(int, s2.split("-"))))
|
|
|
|
def part1(self) -> Any:
|
|
return sum((s1[0] <= s2[0] and s1[1] >= s2[1]) or (s2[0] <= s1[0] and s2[1] >= s1[1]) for s1, s2 in self.get_sections())
|
|
|
|
def part2(self) -> Any:
|
|
return sum(s1[0] <= s2[0] <= s1[1] or s2[0] <= s1[0] <= s2[1] for s1, s2 in self.get_sections())
|
|
|
|
|
|
if __name__ == '__main__':
|
|
day = Day(2022, 4)
|
|
day.run(verbose=True)
|