From b44b5400207a49648caca7b3179f3e145ef63132 Mon Sep 17 00:00:00 2001 From: Bauke Date: Fri, 8 Dec 2023 17:38:52 +0100 Subject: [PATCH] Fix Clippy issues. --- source/year_2020/day_14/mod.rs | 16 ++-------------- source/year_2021/day_05/mod.rs | 24 ++++++------------------ source/year_2021/day_06/mod.rs | 2 +- 3 files changed, 9 insertions(+), 33 deletions(-) diff --git a/source/year_2020/day_14/mod.rs b/source/year_2020/day_14/mod.rs index 1c1c946..5f52c10 100644 --- a/source/year_2020/day_14/mod.rs +++ b/source/year_2020/day_14/mod.rs @@ -32,13 +32,7 @@ fn part_1(input: &str) -> Result { } } - Ok( - memory - .iter() - .map(|(_, value)| value) - .sum::() - .to_string(), - ) + Ok(memory.values().sum::().to_string()) } fn part_2(input: &str) -> Result { @@ -98,13 +92,7 @@ fn part_2(input: &str) -> Result { } } - Ok( - memory - .iter() - .map(|(_, value)| *value) - .sum::() - .to_string(), - ) + Ok(memory.values().sum::().to_string()) } fn combine(input: String) -> Vec { diff --git a/source/year_2021/day_05/mod.rs b/source/year_2021/day_05/mod.rs index 1526769..2582f20 100644 --- a/source/year_2021/day_05/mod.rs +++ b/source/year_2021/day_05/mod.rs @@ -15,30 +15,18 @@ impl Vector { let x_coordinates = { let x_amount = (self.a.0 - self.b.0).abs(); if self.a.0 < self.b.0 { - (0..=x_amount) - .into_iter() - .map(|x| self.a.0 + x) - .collect::>() + (0..=x_amount).map(|x| self.a.0 + x).collect::>() } else { - (0..=x_amount) - .into_iter() - .map(|x| self.a.0 - x) - .collect::>() + (0..=x_amount).map(|x| self.a.0 - x).collect::>() } }; let y_coordinates = { let y_amount = (self.a.1 - self.b.1).abs(); if self.a.1 < self.b.1 { - (0..=y_amount) - .into_iter() - .map(|x| self.a.1 + x) - .collect::>() + (0..=y_amount).map(|x| self.a.1 + x).collect::>() } else { - (0..=y_amount) - .into_iter() - .map(|x| self.a.1 - x) - .collect::>() + (0..=y_amount).map(|x| self.a.1 - x).collect::>() } }; @@ -54,7 +42,7 @@ impl Vector { (self.b.0, self.a.0) }; - (x1..=x2).into_iter().map(|x| (x, y)).collect() + (x1..=x2).map(|x| (x, y)).collect() } fn vertical_coordinates(&self) -> Vec<(isize, isize)> { @@ -66,7 +54,7 @@ impl Vector { (self.b.1, self.a.1) }; - (y1..=y2).into_iter().map(|y| (x, y)).collect() + (y1..=y2).map(|y| (x, y)).collect() } } diff --git a/source/year_2021/day_06/mod.rs b/source/year_2021/day_06/mod.rs index cb6e7d4..c4a22df 100644 --- a/source/year_2021/day_06/mod.rs +++ b/source/year_2021/day_06/mod.rs @@ -43,7 +43,7 @@ fn parse_fishes(input: &str) -> Result { } fn count_fishes(fishes: FishMap) -> isize { - fishes.into_iter().map(|(_, amount)| amount).sum() + fishes.values().sum() } fn simulate_fishes(fishes: FishMap) -> FishMap {