From 00731fd04963873b99e8a1d2571f27c87d8b7658 Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Mon, 20 Dec 2021 17:06:27 +0300 Subject: thanks clippy --- 2021/day9/src/main.rs | 49 ++++++++++++++++++------------------------------- 1 file changed, 18 insertions(+), 31 deletions(-) diff --git a/2021/day9/src/main.rs b/2021/day9/src/main.rs index 3c8d4c6..5d84be9 100644 --- a/2021/day9/src/main.rs +++ b/2021/day9/src/main.rs @@ -39,25 +39,19 @@ fn main() { for (ndx, num) in height.iter().enumerate() { let up = points .get(((idx as isize) - 1) as usize) - .unwrap_or_else(|| &nine) + .unwrap_or(&nine) .get(ndx) - .unwrap_or_else(|| &9); + .unwrap_or(&9); let down = match points.get(idx + 1) { - Some(line) => match line.get(ndx) { - Some(number) => number, - None => &9, - }, - None => &9, - }; - let left = match height.get((ndx as isize - 1) as usize) { - Some(number) => number, - None => &9, - }; - let right = match height.get(ndx + 1) { - Some(number) => number, + Some(line) => line.get(ndx).unwrap_or(&9), None => &9, }; + + let left = height.get((ndx as isize - 1) as usize).unwrap_or(&9); + + let right = height.get(ndx + 1).unwrap_or(&9); + if num < up && num < down && num < right && num < left { risk_level += 1 + *num; basins.push(Basin { @@ -81,29 +75,22 @@ fn main() { let up = points .get(((minibasin.x as isize) - 1) as usize) - .unwrap_or_else(|| &nine) + .unwrap_or(&nine) .get(minibasin.y) - .unwrap_or_else(|| &9); + .unwrap_or(&9); let down = match points.get(minibasin.x + 1) { - Some(line) => match line.get(minibasin.y) { - Some(number) => number, - None => &9, - }, + Some(line) => line.get(minibasin.y).unwrap_or(&9), None => &9, }; let left = match points.get(minibasin.x) { - Some(line) => match line.get(((minibasin.y as isize) - 1) as usize) { - Some(number) => number, - None => &9, - }, + Some(line) => line + .get(((minibasin.y as isize) - 1) as usize) + .unwrap_or(&9), None => &9, }; let right = match points.get(minibasin.x) { - Some(line) => match line.get(minibasin.y + 1) { - Some(number) => number, - None => &9, - }, + Some(line) => line.get(minibasin.y + 1).unwrap_or(&9), None => &9, }; @@ -163,12 +150,12 @@ fn main() { let mut lens: Vec = basins.iter().map(|x| x.points.len()).collect(); - lens.sort(); + lens.sort_unstable(); lens.reverse(); - let foo: usize = lens.iter().take(3).product(); + let biggest_basins: usize = lens.iter().take(3).product(); - println!("{}", foo); + println!("{}", biggest_basins); println!("{}", risk_level); } -- cgit v1.2.3-70-g09d2