Files
python-aoc-2020/day12/part1.py
2020-12-12 12:33:04 +01:00

16 lines
415 B
Python

lines = ((x[0], int(x[1:].strip())) for x in open("input.txt"))
pos = 0
direction = 1
targets = {"E": 1, "N": 1j, "W": -1, "S": -1j}
angles = {"L": 1, "R": -1}
forward = {"F": 1}
for cmd, num in lines:
pos += targets.get(cmd, 0) * num
times = angles.get(cmd, 0) * num / 90
direction = direction * 1j ** times
pos += forward.get(cmd, 0) * direction * num
print(int(abs(pos.real) + abs(pos.imag)))