Skip to content

Commit

Permalink
Merge pull request #122 from wimglenn/2024/10
Browse files Browse the repository at this point in the history
day 10
  • Loading branch information
wimglenn authored Dec 23, 2024
2 parents 582f6e3 + c753e08 commit e40a2a9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
24 changes: 24 additions & 0 deletions aoc_wim/aoc2024/q10.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
--- Day 10: Hoof It ---
https://adventofcode.com/2024/day/10
"""
from aocd import data
import networkx as nx
from aoc_wim.zgrid import ZGrid

grid = ZGrid(data, transform=int)
graph = nx.DiGraph()
for z0, n in grid.items():
for z in grid.near(z0):
if grid.get(z, n) - n == 1:
graph.add_edge(z0, z)

a = b = 0
for head in grid.z(0, first=False):
for peak in grid.z(9, first=False):
paths = list(nx.all_simple_paths(graph, head, peak))
a += bool(paths)
b += len(paths)

print("answer_a:", a)
print("answer_b:", b)
10 changes: 10 additions & 0 deletions tests/2024/10/0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
89010123
78121874
87430965
96549874
45678903
32019012
01329801
10456732
36
81

0 comments on commit e40a2a9

Please sign in to comment.