diff --git a/day12/part1.py b/day12/part1.py index 2f5f6d7..388a5f0 100644 --- a/day12/part1.py +++ b/day12/part1.py @@ -4,14 +4,12 @@ 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: - if cmd in targets: - pos += targets[cmd] * num - elif cmd in angles: - times = angles[cmd] * num / 90 - direction = direction * 1j ** times - else: - pos += direction * num + 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))) diff --git a/day12/part2.py b/day12/part2.py index 8381b0f..a35326a 100644 --- a/day12/part2.py +++ b/day12/part2.py @@ -4,14 +4,12 @@ pos = 0 direction = 10 + 1j targets = {"E": 1, "N": 1j, "W": -1, "S": -1j} angles = {"L": 1, "R": -1} +forward = {"F": 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 + direction += 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)))