aoc2022/day04.py
2022-12-04 09:00:07 +01:00

42 lines
985 B
Python

from tools.aoc import AOCDay
from typing import Any
class Day(AOCDay):
inputs = [
[
(2, "input4_test"),
(528, "input4"),
],
[
(4, "input4_test"),
(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:
count = 0
for s1, s2 in self.get_sections():
if (s1[0] <= s2[0] and s1[1] >= s2[1]) or (s2[0] <= s1[0] and s2[1] >= s1[1]):
count += 1
return count
def part2(self) -> Any:
count = 0
for s1, s2 in self.get_sections():
if s1[0] <= s2[0] <= s1[1] or s2[0] <= s1[0] <= s2[1]:
count += 1
return count
if __name__ == '__main__':
day = Day(2022, 4)
day.run(verbose=True)