-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path03.b.py
More file actions
32 lines (30 loc) · 724 Bytes
/
03.b.py
File metadata and controls
32 lines (30 loc) · 724 Bytes
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
with open("2015/03.input.txt", encoding="utf-8") as file:
data = file.read()
houses: set[tuple[int, int]] = {(0, 0)}
x, y = 0, 0
rx, ry = 0, 0
robo = False
for direction in data:
if robo:
if direction == "^":
ry += 1
elif direction == "v":
ry -= 1
elif direction == ">":
rx += 1
elif direction == "<":
rx -= 1
houses.add((rx, ry))
robo = False
else:
if direction == "^":
y += 1
elif direction == "v":
y -= 1
elif direction == ">":
x += 1
elif direction == "<":
x -= 1
houses.add((x, y))
robo = True
print(len(houses))