Co-authored-by: Mikael CAPELLE <mikael.capelle@thalesaleniaspace.com> Co-authored-by: Mikaël Capelle <capelle.mikael@gmail.com> Reviewed-on: #3
21 lines
591 B
Python
21 lines
591 B
Python
from typing import Any, Iterator
|
|
|
|
from ..base import BaseSolver
|
|
|
|
|
|
def make_range(value: str) -> set[int]:
|
|
parts = value.split("-")
|
|
return set(range(int(parts[0]), int(parts[1]) + 1))
|
|
|
|
|
|
class Solver(BaseSolver):
|
|
def solve(self, input: str) -> Iterator[Any]:
|
|
lines = [line.strip() for line in input.splitlines()]
|
|
|
|
sections = [
|
|
tuple(make_range(part) for part in line.split(",")) for line in lines
|
|
]
|
|
|
|
yield sum(s1.issubset(s2) or s2.issubset(s1) for s1, s2 in sections)
|
|
yield sum(bool(s1.intersection(s2)) for s1, s2 in sections)
|