Compare commits

..

No commits in common. "b296e35b85c3c497643237b497aaa38a83c26141" and "aedcdeaf39d07042e749255780a6100c4df53057" have entirely different histories.

5 changed files with 8 additions and 33 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.2 KiB

View File

@ -2,7 +2,7 @@
<!-- AOC TILES BEGIN -->
<h1 align="center">
2024 - 32 ⭐ - Python
2024 - 26 ⭐ - Python
</h1>
<a href="day01.py">
<img src=".aoc_tiles/tiles/2024/01.png" width="161px">
@ -43,13 +43,4 @@
<a href="day13.py">
<img src=".aoc_tiles/tiles/2024/13.png" width="161px">
</a>
<a href="day14.py">
<img src=".aoc_tiles/tiles/2024/14.png" width="161px">
</a>
<a href="day15.py">
<img src=".aoc_tiles/tiles/2024/15.png" width="161px">
</a>
<a href="day16.py">
<img src=".aoc_tiles/tiles/2024/16.png" width="161px">
</a>
<!-- AOC TILES END -->

View File

@ -30,35 +30,16 @@ def get_best_score(grid: Grid) -> tuple[int, set[Coordinate]]:
def get_tiles_from_all_paths(grid: Grid) -> int:
target_score, target_path = get_best_score(grid)
target = Coordinate(grid.maxX - 1, 1)
path_scores = {}
score = 0
facing = Coordinate(1, 0)
pos = Coordinate(1, grid.maxY - 1)
visited = set()
while pos != target:
visited.add(pos)
for n in pos.getNeighbours(includeDiagonal=False):
if n not in target_path or n in visited:
continue
if n - pos != facing:
score += 1000
facing = n - pos
path_scores[pos] = score
pos = n
score += 1
queue = [(0, Coordinate(1, grid.maxY - 1), Coordinate(1, 0), {Coordinate(1, grid.maxY - 1)})]
# all_paths = set()
visited = {}
while queue:
score, pos, facing, path = heappop(queue)
if pos in visited and score > visited[pos][0] + 1000:
continue
if pos in path_scores and pos in visited:
if score <= path_scores[pos]:
if pos in target_path and pos in visited:
# print(f"{pos} in target_path and visited. {score=}, {visited[pos]=}, discarding {path=}")
if score <= visited[pos][0] or score == visited[pos][0] + 1000:
target_path |= path
continue
@ -77,6 +58,9 @@ def get_tiles_from_all_paths(grid: Grid) -> int:
add_turn = 1001 if n - pos != facing else 1
heappush(queue, (score + add_turn, n, n - pos, path | {n}))
for p in target_path:
grid.set(p, "O")
grid.print()
return len(target_path)