35 lines
725 B
Python
35 lines
725 B
Python
import sys
|
|
from collections import defaultdict
|
|
|
|
line = sys.stdin.read().strip()
|
|
|
|
|
|
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
|
|
|
|
|
|
answer_1 = len(process(line))
|
|
print(f"answer 1 is {answer_1}")
|
|
|
|
answer_2 = len(process(line[::2]) | process(line[1::2]))
|
|
print(f"answer 2 is {answer_2}")
|