Solution to problem 12 in Python
This commit is contained in:
@@ -57,7 +57,7 @@ with open("files/P12.txt", "r") as f:
|
|||||||
|
|
||||||
def part_1() -> None:
|
def part_1() -> None:
|
||||||
# dirs are E, S, W, and N
|
# 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_pos = [0, 0]
|
||||||
current_dir = 0
|
current_dir = 0
|
||||||
|
|
||||||
@@ -72,8 +72,8 @@ def part_1() -> None:
|
|||||||
elif _dir == "S":
|
elif _dir == "S":
|
||||||
current_pos[1] -= int(_num)
|
current_pos[1] -= int(_num)
|
||||||
elif _dir == "F":
|
elif _dir == "F":
|
||||||
current_pos[0] += int(_num) * _dirs[current_dir][0]
|
current_pos[0] += int(_num) * dirs[current_dir][0]
|
||||||
current_pos[1] += int(_num) * _dirs[current_dir][1]
|
current_pos[1] += int(_num) * dirs[current_dir][1]
|
||||||
else:
|
else:
|
||||||
if _dir == "R":
|
if _dir == "R":
|
||||||
# rotations are clockwise
|
# rotations are clockwise
|
||||||
|
|||||||
Reference in New Issue
Block a user