diff --git a/day12/part1.py b/day12/part1.py index e177190..5ae018e 100644 --- a/day12/part1.py +++ b/day12/part1.py @@ -5,13 +5,13 @@ drctn = 1 targets = [1j, 1, -1j, -1] target_str = "NESW" -for line in lines: - if line[0] in target_str: - pos += targets[target_str.index(line[0])] * line[1] - elif line[0] in "LR": - times = (-line[1] if line[0] == "R" else line[1]) / 90 +for cmd, num in lines: + if cmd in target_str: + pos += targets[target_str.index(cmd)] * num + elif cmd in "LR": + times = (-1 if cmd == "R" else 1) * num / 90 drctn = drctn * 1j ** times else: - pos += drctn * line[1] + pos += drctn * num print(int(abs(pos.real) + abs(pos.imag))) diff --git a/day12/part2.py b/day12/part2.py index 53a4864..d758a86 100644 --- a/day12/part2.py +++ b/day12/part2.py @@ -5,13 +5,13 @@ 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 +for cmd, num in lines: + if cmd in target_str: + drctn += targets[target_str.index(cmd)] * num + elif cmd in "LR": + times = (-1 if cmd == "R" else 1) * num / 90 drctn = drctn * 1j ** times else: - pos += drctn * line[1] + pos += drctn * num print(int(abs(pos.real) + abs(pos.imag)))