-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
37 lines (28 loc) · 892 Bytes
/
main.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 enum
class Direction(enum.Enum):
Right = 0
Down = 1
Left = 2
Up = 3
def turn(self, ntimes=1):
return Direction((self.value + ntimes) % 4)
def move(self, x, y, ntimes=1):
if self == Direction.Right:
return x + ntimes, y
elif self == Direction.Down:
return x, y + ntimes
elif self == Direction.Left:
return x - ntimes, y
elif self == Direction.Up:
return x, y - ntimes
def main(data):
x, y, d = data["x"], data["y"], Direction.Right
visited = [(x, y)]
for command, ntimes in data["cmds"]:
for i in range(ntimes):
if command == "F":
x, y = d.move(x, y)
visited.append((x, y))
elif command == "T":
d = d.turn()
return "\n".join(["{} {}".format(x, y) for x, y in visited])