-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6e1b999
commit 4caf207
Showing
5 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
89010123 | ||
78121874 | ||
87430965 | ||
96549874 | ||
45678903 | ||
32019012 | ||
01329801 | ||
10456732 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
0123 | ||
1234 | ||
8765 | ||
9876 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters