40 lines
817 B
Python
40 lines
817 B
Python
|
""" day 6 part 1 """
|
||
|
|
||
|
import fileinput
|
||
|
|
||
|
room = [line for line in fileinput.input()]
|
||
|
|
||
|
guard_x = None
|
||
|
guard_y = None
|
||
|
|
||
|
for y,line in enumerate(room):
|
||
|
for x,cell in enumerate(line):
|
||
|
if cell in '^<>v':
|
||
|
guard_x = x
|
||
|
guard_y = y
|
||
|
guard_d = cell
|
||
|
|
||
|
dirs = {
|
||
|
'^': (0,-1,'>'),
|
||
|
'>': (1,0,'v'),
|
||
|
'v': (0,1,'<'),
|
||
|
'<': (-1,0,'^')
|
||
|
}
|
||
|
|
||
|
visited = {}
|
||
|
|
||
|
while 0 <= guard_y < len(room) and 0 <= guard_x < len(room[guard_y]):
|
||
|
dx, dy, turn = dirs[guard_d]
|
||
|
|
||
|
print(guard_x,guard_y,guard_d)
|
||
|
step_x = guard_x + dx
|
||
|
step_y = guard_y + dy
|
||
|
|
||
|
if 0 <= step_y < len(room) and 0 <= step_x < len(room[step_y]) and room[step_y][step_x] == '#':
|
||
|
guard_d = turn
|
||
|
else:
|
||
|
visited.add((guard_x,guard_y))
|
||
|
guard_x,guard_y = step_x,step_y
|
||
|
|
||
|
print(len(visited))
|