From f8abb73ad29fb8f59b0477926d109af545ad8ee9 Mon Sep 17 00:00:00 2001 From: Sebastian Seedorf Date: Sat, 12 Dec 2020 12:08:50 +0100 Subject: [PATCH] Day 12 (split line to (cmd, num)) --- day12/part1.py | 12 ++++++------ day12/part2.py | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) 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)))