4
4
5
5
Point = namedtuple ("Point" , ['x' , 'y' ])
6
6
7
+ def tile_cave (cave : Dict [Point , int ], size : Point ) -> Tuple [Dict [Point , int ], Point ]:
8
+ new_cave = dict ()
9
+
10
+ for y_tile in range (5 ):
11
+ for x_tile in range (5 ):
12
+ for y in range (size .y ):
13
+ tiled_y = y_tile * size .y + y
14
+ for x in range (size .x ):
15
+ old_loc = Point (x = x ,y = y )
16
+ tiled_x = x_tile * size .x + x
17
+ tiled_loc = Point (x = tiled_x , y = tiled_y )
18
+ new_cave [tiled_loc ] = cave [old_loc ] + y_tile + x_tile
19
+ if new_cave [tiled_loc ] > 9 :
20
+ new_cave [tiled_loc ] -= 9
21
+ return new_cave , Point (x = size .x * 5 ,y = size .y * 5 )
22
+
23
+
7
24
def read_input (textio : TextIO ):
8
25
cave = dict ()
9
26
max_x = max_y = 0
@@ -16,7 +33,10 @@ def read_input(textio: TextIO):
16
33
max_y = max (max_y , y )
17
34
cave [loc ] = value
18
35
19
- return cave , Point (x = max_x + 1 , y = max_y + 1 )
36
+ size = Point (x = max_x + 1 , y = max_y + 1 )
37
+ cave , size = tile_cave (cave , size )
38
+
39
+ return cave , size
20
40
21
41
def neighbors (location : Point , size : Point ):
22
42
for x_delta , y_delta in [(0 ,1 ), (0 , - 1 ), (1 ,0 ), (- 1 ,0 )]:
@@ -36,7 +56,7 @@ def visit(cave: Dict[Point, int], size: Point) -> Dict[Point, Tuple[int, Optiona
36
56
if node_to in visited :
37
57
if new_cost < visited [node_to ][0 ]:
38
58
visited [node_to ] = (new_cost , node_from )
39
- to_visit .extend (neighbors (node_to , size ))
59
+ to_visit .extend (neighbors (node_to , size )) # This could probably be more efficient
40
60
else :
41
61
pass
42
62
else :
@@ -71,5 +91,5 @@ def print_cave(cave: Dict[Point, int], size: Point, path: List[Point]):
71
91
visits = visit (cave , size )
72
92
73
93
path = find_path (cave , visits , finish )
74
- print_cave (cave , size , path )
94
+ # print_cave(cave, size, path)
75
95
print (visits [finish ][0 ])
0 commit comments