finish 82

This commit is contained in:
Dr. Matthias Ratajczak
2022-09-27 14:05:32 +02:00
parent 6da8e3d651
commit f545a592bd
3 changed files with 22 additions and 13 deletions
+9 -7
View File
@@ -17,14 +17,14 @@ impl AllowedMovements {
}
}
fn get_neighbours_down_right(&self, (x0, y0): &Coordinate) -> Vec<Coordinate> {
vec![(*x0 + 1, *y0), (*x0, *y0 + 1)]
fn get_neighbours_down_right(&self, (x, y): &Coordinate) -> Vec<Coordinate> {
vec![(*x + 1, *y), (*x, *y + 1)]
}
fn get_neighbours_down_right_up(&self, (x0, y0): &Coordinate) -> Vec<Coordinate> {
let mut result = self.get_neighbours_down_right(&(*x0, *y0));
if *y0 > 0 {
result.push((*x0, *y0 - 1));
fn get_neighbours_down_right_up(&self, (x, y): &Coordinate) -> Vec<Coordinate> {
let mut result = self.get_neighbours_down_right(&(*x, *y));
if *y > 0 {
result.push((*x, *y - 1));
}
result
}
@@ -51,6 +51,7 @@ pub struct Dijkstra<'a, T> {
unvisited_with_distance: HashSet<Coordinate>,
unvisited_without_distance: HashSet<Coordinate>,
allowed_movements: AllowedMovements,
start: Coordinate,
}
impl<'a, T> Debug for Dijkstra<'a, T> {
@@ -77,6 +78,7 @@ where
unvisited_with_distance,
unvisited_without_distance,
allowed_movements,
start,
}
}
@@ -103,7 +105,7 @@ where
})
.reduce(|(c0, v0), (c1, v1)| if v0 < v1 { (c0, v0) } else { (c1, v1) })
.map(|(c, _)| *c)
.unwrap_or((0, 0));
.unwrap_or(self.start);
self.unvisited_with_distance.remove(&coord);
coord
}