finish 82
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user