diff --git a/2015/d03.py b/2015/d03.py index 5a64fe9..1bf22f1 100755 --- a/2015/d03.py +++ b/2015/d03.py @@ -7,12 +7,7 @@ SAMPLE = ["^>v<", "^v^v^v^v^v"] InputType = list[str] -MAPPING = { - "^": complex(0, +1), - "v": complex(0, -1), - "<": complex(-1, 0), - ">": complex(+1, 0), -} +MAPPING = aoc.ARROW_DIRECTIONS class Day03(aoc.Challenge): diff --git a/2018/d13.py b/2018/d13.py index 25f072d..85b8234 100755 --- a/2018/d13.py +++ b/2018/d13.py @@ -39,12 +39,9 @@ ROT_STRAIGHT = complex(1, -0) ROT_RIGHT = complex(0, 1) ROTATIONS = [ROT_LEFT, ROT_STRAIGHT, ROT_RIGHT] -UP = complex(0, -1) -DOWN = complex(0, 1) -LEFT = complex(-1, 0) -RIGHT = complex(1, 0) +UP, DOWN, RIGHT, LEFT = aoc.FOUR_DIRECTIONS -DIRECTIONS = {"^": UP, "v": DOWN, "<": LEFT, ">": RIGHT} +DIRECTIONS = aoc.ARROW_DIRECTIONS CORNERS = { "/": {UP: RIGHT, LEFT: DOWN, RIGHT: UP, DOWN: LEFT}, "\\": {UP: LEFT, LEFT: UP, RIGHT: DOWN, DOWN: RIGHT}, diff --git a/2022/d17.py b/2022/d17.py index ffea60f..65c6dbe 100755 --- a/2022/d17.py +++ b/2022/d17.py @@ -59,7 +59,7 @@ def solver(self, puzzle_input: InputType, part_one: bool) -> int: stream = puzzle_input stream_size = len(stream) # Wind directions, translated to a number. - wind_direction = [{"<": -1, ">": 1}[i] for i in stream] + wind_direction = [aoc.ARROW_DIRECTIONS[i] for i in stream] # Index counter which wraps around. wind_idx_iter = itertools.cycle(range(stream_size)) diff --git a/2022/d24.py b/2022/d24.py index 386b3b8..ec11544 100755 --- a/2022/d24.py +++ b/2022/d24.py @@ -69,7 +69,7 @@ def input_parser(cls, puzzle_input: str) -> Basin: if char == ".": continue positions[char].add(complex(x_pos, y_pos)) - char_to_dir = {">": 1, "<": -1, "v": 1j, "^": -1j} + char_to_dir = aoc.ARROW_DIRECTIONS blizzards = {direction: positions[char] for char, direction in char_to_dir.items()} return cls( walls=positions["#"], diff --git a/pylib/helpers.py b/pylib/helpers.py index 7a94d65..1dd3502 100644 --- a/pylib/helpers.py +++ b/pylib/helpers.py @@ -41,7 +41,7 @@ 'sw': -1 +0j, } -RE_INT = re.compile(r"[+-]?\d{1,1000") +RE_INT = re.compile(r"[+-]?\d{1,1000}") RE_BOUNDED_INT = re.compile(r"[+-]?\b\d+\b") OPERATORS = { ">": operator.gt,