Remove a useless '&mut'.
authorGreg Burri <greg.burri@gmail.com>
Tue, 10 Dec 2024 16:37:03 +0000 (17:37 +0100)
committerGreg Burri <greg.burri@gmail.com>
Tue, 10 Dec 2024 16:37:03 +0000 (17:37 +0100)
src/day10.rs

index a939e60..961e73f 100644 (file)
@@ -46,11 +46,7 @@ pub fn score(map: &Map, start_positions: &[Position], multiple_paths: bool) -> u
         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;
@@ -64,11 +60,11 @@ pub fn score(map: &Map, start_positions: &[Position], multiple_paths: bool) -> u
         } 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()
@@ -78,14 +74,13 @@ pub fn score(map: &Map, start_positions: &[Position], multiple_paths: bool) -> u
     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