Skip to content

Commit

Permalink
[2024/10] p1 & p2 solved
Browse files Browse the repository at this point in the history
  • Loading branch information
StarlitGhost committed Dec 10, 2024
1 parent 6e1b999 commit 4caf207
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 1 deletion.
Binary file modified .aoc_tiles/tiles/2024/10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions 2024/10/example_l
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
89010123
78121874
87430965
96549874
45678903
32019012
01329801
10456732
4 changes: 4 additions & 0 deletions 2024/10/example_s
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
0123
1234
8765
9876
41 changes: 41 additions & 0 deletions 2024/10/script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from GhostyUtils import aoc
from GhostyUtils.grid import Grid
from GhostyUtils.pathfinding import dfs
import functools


def passable(current_pos, next_pos, *, grid: Grid):
if grid[next_pos] == grid[current_pos] + 1:
return True
return False


def max_height(current_pos, *, grid: Grid):
return grid[current_pos] == 9


def main():
grid = Grid(aoc.read_lines(), convert=int)
if aoc.args.verbose:
print(grid)

passable_func = functools.partial(passable, grid=grid)
neighbours = functools.partial(grid.neighbours, diagonal=False, connects=passable_func)
early_out = functools.partial(max_height, grid=grid)

total_score = 0
total_rating = 0
for trailhead in grid.find_all(0):
ends = set()
for path in dfs(start=trailhead, end=None, all_paths=True,
neighbours=neighbours, early_out=early_out):
ends.add(path[-1])
total_rating += 1
total_score += len(ends)

print(f"p1: {total_score}")
print(f"p2: {total_rating}")


if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ My solutions to the yearly Advents of Code
<a href="2024/9/script.py">
<img src=".aoc_tiles/tiles/2024/09.png" width="161px">
</a>
<a href="None">
<a href="2024/10/script.py">
<img src=".aoc_tiles/tiles/2024/10.png" width="161px">
</a>
<h1 align="center">
Expand Down

0 comments on commit 4caf207

Please sign in to comment.