from collections import defaultdict from typing import Any, Iterator from ..base import BaseSolver def process(directions: str) -> dict[tuple[int, int], int]: counts: dict[tuple[int, int], int] = defaultdict(lambda: 0) counts[0, 0] = 1 x, y = (0, 0) for c in directions: match c: case ">": x += 1 case "<": x -= 1 case "^": y -= 1 case "v": y += 1 case _: raise ValueError() counts[x, y] += 1 return counts class Solver(BaseSolver): def solve(self, input: str) -> Iterator[Any]: yield len(process(input)) yield len(process(input[::2]) | process(input[1::2]))