-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11.py
38 lines (38 loc) · 954 Bytes
/
11.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
f = open("11.in")
obstacles = []
visited = set()
pos = (0,0)
dir = "up"
for i, line in enumerate(f.readlines()):
for j, spot in enumerate(line):
if spot == "#":
obstacles.append((i,j))
elif spot == "^":
pos = (i,j)
while pos[0] < 130 and pos[0] >= 0 and pos[1] < 130 and pos[1] >= 0:
visited.add(pos)
if dir == "up":
next = (pos[0]-1,pos[1])
if next in obstacles:
dir = "right"
else:
pos = next
if dir == "right":
next = (pos[0],pos[1]+1)
if next in obstacles:
dir = "down"
else:
pos = next
if dir == "down":
next = (pos[0]+1,pos[1])
if next in obstacles:
dir = "left"
else:
pos = next
if dir == "left":
next = (pos[0],pos[1]-1)
if next in obstacles:
dir = "up"
else:
pos = next
print(len(visited))