Solution to problem 12 in Python

This commit is contained in:
David Doblas Jiménez 2021-12-08 10:19:41 +01:00
parent 0a24d49137
commit f2e5340136

View File

@ -57,7 +57,7 @@ with open("files/P12.txt", "r") as f:
def part_1() -> None:
# dirs are E, S, W, and N
_dirs = [[1, 0], [0, -1], [-1, 0], [0, 1]]
dirs = [[1, 0], [0, -1], [-1, 0], [0, 1]]
current_pos = [0, 0]
current_dir = 0
@ -72,8 +72,8 @@ def part_1() -> None:
elif _dir == "S":
current_pos[1] -= int(_num)
elif _dir == "F":
current_pos[0] += int(_num) * _dirs[current_dir][0]
current_pos[1] += int(_num) * _dirs[current_dir][1]
current_pos[0] += int(_num) * dirs[current_dir][0]
current_pos[1] += int(_num) * dirs[current_dir][1]
else:
if _dir == "R":
# rotations are clockwise