MCPcopy Create free account
hub / github.com/AxlLind/AdventOfCode / dijkstra

Function dijkstra

2018/src/22.py:30–42  ·  view source on GitHub ↗
(cave: list[list[int]], start: Node, target: Node)

Source from the content-addressed store, hash-verified

28 return ns
29
30def dijkstra(cave: list[list[int]], start: Node, target: Node) -> int:
31 q, costs = [(0,start)], defaultdict[Node,int](lambda: 100000)
32 costs[start] = 0
33 while q:
34 cost,here = heappop(q)
35 if here == target:
36 return cost
37 for c,node in neighbors(cave,here):
38 c += cost
39 if c < costs[node]:
40 costs[node] = c
41 heappush(q, (c,node))
42 assert False
43
44def build_cave(depth: int, rows: int, cols: int) -> tuple[int, list[list[int]]]:
45 cave = [[0 for _ in range(10*cols)] for _ in range(10*rows)]

Callers 1

mainFunction · 0.70

Calls 1

neighborsFunction · 0.85

Tested by

no test coverage detected