Files
python-aoc-2020/day12/part2.py
2020-12-12 12:02:09 +01:00

18 lines
455 B
Python

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