Skip to content

Commit 8c63521

Browse files
committed
Day 15, Part 2
1 parent e43c242 commit 8c63521

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

day_15/__main__.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,23 @@
44

55
Point = namedtuple("Point", ['x', 'y'])
66

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+
724
def read_input(textio: TextIO):
825
cave = dict()
926
max_x = max_y = 0
@@ -16,7 +33,10 @@ def read_input(textio: TextIO):
1633
max_y = max(max_y, y)
1734
cave[loc] = value
1835

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
2040

2141
def neighbors(location: Point, size: Point):
2242
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
3656
if node_to in visited:
3757
if new_cost < visited[node_to][0]:
3858
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
4060
else:
4161
pass
4262
else:
@@ -71,5 +91,5 @@ def print_cave(cave: Dict[Point, int], size: Point, path: List[Point]):
7191
visits = visit(cave, size)
7292

7393
path = find_path(cave, visits, finish)
74-
print_cave(cave, size, path)
94+
# print_cave(cave, size, path)
7595
print(visits[finish][0])

0 commit comments

Comments
 (0)