From: Greg Burri Date: Tue, 10 Dec 2024 16:37:03 +0000 (+0100) Subject: Remove a useless '&mut'. X-Git-Url: https://git.euphorik.ch/?a=commitdiff_plain;h=cc4e535c739ce5764794ab0aaf6f29f8e730ee0f;p=advent_of_code_2024.git Remove a useless '&mut'. --- diff --git a/src/day10.rs b/src/day10.rs index a939e60..961e73f 100644 --- a/src/day10.rs +++ b/src/day10.rs @@ -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>, - ) -> u32 { + fn get_nb_summits((i, j): Position, map: &Map, visited: &mut Option>) -> 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::::repeat(map.nrows(), map.ncols(), false); let n = get_nb_summits( *pos, map, &mut if multiple_paths { None } else { - Some(&mut visited) + Some(DMatrix::::repeat(map.nrows(), map.ncols(), false)) }, ); n