mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
Slihghtly simplify
This commit is contained in:
@@ -15,6 +15,20 @@ def parse_input(data: str) -> tuple[numpy.array, str]:
|
|||||||
return grid_split, steps
|
return grid_split, steps
|
||||||
|
|
||||||
|
|
||||||
|
def convert_dir(c: str) -> tuple[int, int]:
|
||||||
|
match c:
|
||||||
|
case "^":
|
||||||
|
return 0, -1
|
||||||
|
case ">":
|
||||||
|
return 1, 0
|
||||||
|
case "<":
|
||||||
|
return -1, 0
|
||||||
|
case "v":
|
||||||
|
return 0, 1
|
||||||
|
case other:
|
||||||
|
raise ValueError(f"Invalid movement: {other}")
|
||||||
|
|
||||||
|
|
||||||
class DayRunner(SeparateRunner):
|
class DayRunner(SeparateRunner):
|
||||||
@classmethod
|
@classmethod
|
||||||
def part1(cls, input: str) -> None:
|
def part1(cls, input: str) -> None:
|
||||||
@@ -24,17 +38,7 @@ class DayRunner(SeparateRunner):
|
|||||||
x, y = x[0], y[0]
|
x, y = x[0], y[0]
|
||||||
|
|
||||||
for c in steps:
|
for c in steps:
|
||||||
match c:
|
dx, dy = convert_dir(c)
|
||||||
case "^":
|
|
||||||
dx, dy = 0, -1
|
|
||||||
case ">":
|
|
||||||
dx, dy = 1, 0
|
|
||||||
case "<":
|
|
||||||
dx, dy = -1, 0
|
|
||||||
case "v":
|
|
||||||
dx, dy = 0, 1
|
|
||||||
case other:
|
|
||||||
raise ValueError(f"Invalid movement: {other}")
|
|
||||||
|
|
||||||
match grid[y + dy, x + dx]:
|
match grid[y + dy, x + dx]:
|
||||||
case "#":
|
case "#":
|
||||||
@@ -81,17 +85,7 @@ class DayRunner(SeparateRunner):
|
|||||||
x, y = x[0], y[0]
|
x, y = x[0], y[0]
|
||||||
|
|
||||||
for c in steps:
|
for c in steps:
|
||||||
match c:
|
dx, dy = convert_dir(c)
|
||||||
case "^":
|
|
||||||
dx, dy = 0, -1
|
|
||||||
case ">":
|
|
||||||
dx, dy = 1, 0
|
|
||||||
case "<":
|
|
||||||
dx, dy = -1, 0
|
|
||||||
case "v":
|
|
||||||
dx, dy = 0, 1
|
|
||||||
case other:
|
|
||||||
raise ValueError(f"Invalid movement: {other}")
|
|
||||||
|
|
||||||
match grid[y + dy, x + dx]:
|
match grid[y + dy, x + dx]:
|
||||||
case "#":
|
case "#":
|
||||||
|
|||||||
Reference in New Issue
Block a user