positions
}
- fn get_nb_summits(
- (i, j): Position,
- map: &Map,
- visited: &mut Option<&mut DMatrix<bool>>,
- ) -> u32 {
+ fn get_nb_summits((i, j): Position, map: &Map, visited: &mut Option<DMatrix<bool>>) -> u32 {
if let Some(visited) = visited.as_mut() {
if visited[(i, j)] {
return 0;
} else {
neighbors((i, j), map.ncols(), map.nrows())
.into_iter()
- .filter_map(|(i2, j2)| {
+ .map(|(i2, j2)| {
if map[(i2, j2)] == map[(i, j)] + 1 {
- Some(get_nb_summits((i2, j2), map, visited))
+ get_nb_summits((i2, j2), map, visited)
} else {
- None
+ 0
}
})
.sum()
start_positions
.into_iter()
.map(|pos| {
- let mut visited = DMatrix::<bool>::repeat(map.nrows(), map.ncols(), false);
let n = get_nb_summits(
*pos,
map,
&mut if multiple_paths {
None
} else {
- Some(&mut visited)
+ Some(DMatrix::<bool>::repeat(map.nrows(), map.ncols(), false))
},
);
n