Skip to content

Commit

Permalink
Reuse ARROW DIRECTIONS
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacG committed Dec 15, 2024
1 parent 365f4bc commit 2c997f2
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 14 deletions.
7 changes: 1 addition & 6 deletions 2015/d03.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
7 changes: 2 additions & 5 deletions 2018/d13.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
2 changes: 1 addition & 1 deletion 2022/d17.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
2 changes: 1 addition & 1 deletion 2022/d24.py
Original file line number Diff line number Diff line change
Expand Up @@ -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["#"],
Expand Down
2 changes: 1 addition & 1 deletion pylib/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 2c997f2

Please sign in to comment.