diff options
| author | Reiner Herrmann <reiner@reiner-h.de> | 2021-12-15 23:45:48 +0100 |
|---|---|---|
| committer | Reiner Herrmann <reiner@reiner-h.de> | 2021-12-15 23:45:48 +0100 |
| commit | 0ec36c5eb209f3524230374e754aee94899fecec (patch) | |
| tree | d2ccadf6cec4b6d7ac26e90c171ce18f0b312f38 | |
| parent | e9873553756966f5d778e6d6d043476e81e4fcfe (diff) | |
fix cost lookup
| -rw-r--r-- | src/bin/day15.rs | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/bin/day15.rs b/src/bin/day15.rs index ef8c238..a6c293d 100644 --- a/src/bin/day15.rs +++ b/src/bin/day15.rs @@ -56,7 +56,7 @@ fn dijkstra(map: &HashMap<Position, isize>, from: &Position, to: &Position) -> i if !map.contains_key(&neigh_pos) { continue; } - let neigh = State { cost: cost + *map.get(&pos).unwrap(), pos: neigh_pos }; + let neigh = State { cost: cost + *map.get(&neigh_pos).unwrap(), pos: neigh_pos }; if neigh.cost < dist[&neigh.pos] { heap.push(neigh); dist.insert(neigh.pos, neigh.cost); @@ -85,7 +85,7 @@ fn lowest_risk<T: AsRef<str>>(input: &[T]) -> isize { let start = Position { x: 0, y: 0 }; let end = *map.keys().max_by_key(|&pos| pos.x + pos.y).unwrap(); - dijkstra(&map, &end, &start) + dijkstra(&map, &start, &end) } fn lowest_risk_large<T: AsRef<str>>(input: &[T]) -> isize { @@ -110,7 +110,7 @@ fn lowest_risk_large<T: AsRef<str>>(input: &[T]) -> isize { } let end = *large_map.keys().max_by_key(|&pos| pos.x + pos.y).unwrap(); - dijkstra(&large_map, &end, &start) + dijkstra(&large_map, &start, &end) } #[cfg(test)] |
