-
Notifications
You must be signed in to change notification settings - Fork 0
/
day-6.1.py
37 lines (28 loc) · 813 Bytes
/
day-6.1.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
import re
from functools import reduce
data = None
position = [-1,-1]
direction = [-1,0]
visits = set()
directions = {
"[-1, 0]":[0,1],
"[0, 1]":[1,0],
"[1, 0]":[0,-1],
"[0, -1]":[-1,0],
}
with open("input.txt",encoding="utf-8") as inpf:
data = [list(x) for x in inpf.read().split("\n")]
for x in range(len(data)):
for y in range(len(data[0])):
if data[x][y] == "^":
position = [x,y]
visits.add(str(position))
while(position[0]+direction[0] in range(len(data)) and position[1]+direction[1] in range(len(data[0]))):
newposition = [position[0]+direction[0],position[1]+direction[1]]
if data[newposition[0]][newposition[1]] != "#":
position = newposition
visits.add(str(position))
else:
direction = directions[str(direction)]
answer = len(visits)
print(answer)