File tree Expand file tree Collapse file tree 1 file changed +16
-22
lines changed Expand file tree Collapse file tree 1 file changed +16
-22
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,20 @@ def parse_input(data: str) -> tuple[numpy.array, str]:
15
15
return grid_split , steps
16
16
17
17
18
+ def convert_dir (c : str ) -> tuple [int , int ]:
19
+ match c :
20
+ case "^" :
21
+ return 0 , - 1
22
+ case ">" :
23
+ return 1 , 0
24
+ case "<" :
25
+ return - 1 , 0
26
+ case "v" :
27
+ return 0 , 1
28
+ case other :
29
+ raise ValueError (f"Invalid movement: { other } " )
30
+
31
+
18
32
class DayRunner (SeparateRunner ):
19
33
@classmethod
20
34
def part1 (cls , input : str ) -> None :
@@ -24,17 +38,7 @@ def part1(cls, input: str) -> None:
24
38
x , y = x [0 ], y [0 ]
25
39
26
40
for c in steps :
27
- match c :
28
- case "^" :
29
- dx , dy = 0 , - 1
30
- case ">" :
31
- dx , dy = 1 , 0
32
- case "<" :
33
- dx , dy = - 1 , 0
34
- case "v" :
35
- dx , dy = 0 , 1
36
- case other :
37
- raise ValueError (f"Invalid movement: { other } " )
41
+ dx , dy = convert_dir (c )
38
42
39
43
match grid [y + dy , x + dx ]:
40
44
case "#" :
@@ -81,17 +85,7 @@ def part2(cls, input: str) -> None:
81
85
x , y = x [0 ], y [0 ]
82
86
83
87
for c in steps :
84
- match c :
85
- case "^" :
86
- dx , dy = 0 , - 1
87
- case ">" :
88
- dx , dy = 1 , 0
89
- case "<" :
90
- dx , dy = - 1 , 0
91
- case "v" :
92
- dx , dy = 0 , 1
93
- case other :
94
- raise ValueError (f"Invalid movement: { other } " )
88
+ dx , dy = convert_dir (c )
95
89
96
90
match grid [y + dy , x + dx ]:
97
91
case "#" :
You can’t perform that action at this time.
0 commit comments