aoc2015/d03/part2.py

29 lines
357 B
Python
Raw Permalink Normal View History

2023-12-01 09:42:13 +00:00
import sys
s = sys.stdin.read()[:-1]
cpS = (0,0)
cpR = (0,0)
P = {cpS}
dep = {
'<':(1,0),
'>':(-1,0),
'v':(0,1),
'^':(0,-1),
}
for i,c in enumerate(s):
dx,dy = dep[c]
if i%2:
x,y = cpS
cpS = (x+dx,y+dy)
P.add(cpS)
else:
x,y = cpR
cpR = (x+dx,y+dy)
P.add(cpR)
print(len(P))