-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay3.py
50 lines (42 loc) · 1.2 KB
/
Day3.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
39
40
41
42
43
44
45
46
47
48
49
from PuzzleInput import ReadInput
pz_input = ReadInput(3).data[0]
def part_a():
visited = [(0, 0)]
x = 0
y = 0
for move in pz_input:
if move == "^":
y += 1
elif move == "v":
y -= 1
elif move == ">":
x += 1
elif move == "<":
x -= 1
else:
raise IndexError(move)
if (x, y) not in visited:
visited.append((x, y))
return len(visited)
def part_b():
visited = [(0, 0)]
loc = [0, 0, 0, 0]
santa = True
for move in pz_input:
if move == "^":
loc[1 + (0 if santa else 2)] += 1
elif move == "v":
loc[1 + (0 if santa else 2)] -= 1
elif move == ">":
loc[0 + (0 if santa else 2)] += 1
elif move == "<":
loc[0 + (0 if santa else 2)] -= 1
else:
raise IndexError(move)
if (loc[0 + (0 if santa else 2)], loc[1 + (0 if santa else 2)]) not in visited:
visited.append((loc[0 + (0 if santa else 2)], loc[1 + (0 if santa else 2)]))
santa = not santa
return len(visited)
if __name__ == "__main__":
print("Part A", part_a())
print("Part B", part_b())