18 lines
445 B
Python
18 lines
445 B
Python
lines = ((x[0], int(x[1:].strip())) for x in open("input.txt"))
|
|
|
|
pos = 0
|
|
direction = 10 + 1j
|
|
targets = {"E": 1, "N": 1j, "W": -1, "S": -1j}
|
|
angles = {"L": 1, "R": -1}
|
|
|
|
for cmd, num in lines:
|
|
if cmd in targets:
|
|
direction += targets[cmd] * num
|
|
elif cmd in angles:
|
|
times = angles[cmd] * num / 90
|
|
direction = direction * 1j ** times
|
|
else:
|
|
pos += direction * num
|
|
|
|
print(int(abs(pos.real) + abs(pos.imag)))
|