18 lines
423 B
Python
18 lines
423 B
Python
lines = ((x[0], int(x[1:].strip())) for x in open("input.txt"))
|
|
|
|
pos = 0
|
|
drctn = 1
|
|
targets = [1j, 1, -1j, -1]
|
|
target_str = "NESW"
|
|
|
|
for cmd, num in lines:
|
|
if cmd in target_str:
|
|
pos += targets[target_str.index(cmd)] * num
|
|
elif cmd in "LR":
|
|
times = (-1 if cmd == "R" else 1) * num / 90
|
|
drctn = drctn * 1j ** times
|
|
else:
|
|
pos += drctn * num
|
|
|
|
print(int(abs(pos.real) + abs(pos.imag)))
|