1
Fork 0

Fix Clippy issues.

This commit is contained in:
Bauke 2023-12-08 17:38:52 +01:00
parent 0951a5930a
commit b44b540020
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
3 changed files with 9 additions and 33 deletions

View File

@ -32,13 +32,7 @@ fn part_1(input: &str) -> Result<String> {
} }
} }
Ok( Ok(memory.values().sum::<i64>().to_string())
memory
.iter()
.map(|(_, value)| value)
.sum::<i64>()
.to_string(),
)
} }
fn part_2(input: &str) -> Result<String> { fn part_2(input: &str) -> Result<String> {
@ -98,13 +92,7 @@ fn part_2(input: &str) -> Result<String> {
} }
} }
Ok( Ok(memory.values().sum::<i64>().to_string())
memory
.iter()
.map(|(_, value)| *value)
.sum::<i64>()
.to_string(),
)
} }
fn combine(input: String) -> Vec<String> { fn combine(input: String) -> Vec<String> {

View File

@ -15,30 +15,18 @@ impl Vector {
let x_coordinates = { let x_coordinates = {
let x_amount = (self.a.0 - self.b.0).abs(); let x_amount = (self.a.0 - self.b.0).abs();
if self.a.0 < self.b.0 { if self.a.0 < self.b.0 {
(0..=x_amount) (0..=x_amount).map(|x| self.a.0 + x).collect::<Vec<_>>()
.into_iter()
.map(|x| self.a.0 + x)
.collect::<Vec<_>>()
} else { } else {
(0..=x_amount) (0..=x_amount).map(|x| self.a.0 - x).collect::<Vec<_>>()
.into_iter()
.map(|x| self.a.0 - x)
.collect::<Vec<_>>()
} }
}; };
let y_coordinates = { let y_coordinates = {
let y_amount = (self.a.1 - self.b.1).abs(); let y_amount = (self.a.1 - self.b.1).abs();
if self.a.1 < self.b.1 { if self.a.1 < self.b.1 {
(0..=y_amount) (0..=y_amount).map(|x| self.a.1 + x).collect::<Vec<_>>()
.into_iter()
.map(|x| self.a.1 + x)
.collect::<Vec<_>>()
} else { } else {
(0..=y_amount) (0..=y_amount).map(|x| self.a.1 - x).collect::<Vec<_>>()
.into_iter()
.map(|x| self.a.1 - x)
.collect::<Vec<_>>()
} }
}; };
@ -54,7 +42,7 @@ impl Vector {
(self.b.0, self.a.0) (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)> { fn vertical_coordinates(&self) -> Vec<(isize, isize)> {
@ -66,7 +54,7 @@ impl Vector {
(self.b.1, self.a.1) (self.b.1, self.a.1)
}; };
(y1..=y2).into_iter().map(|y| (x, y)).collect() (y1..=y2).map(|y| (x, y)).collect()
} }
} }

View File

@ -43,7 +43,7 @@ fn parse_fishes(input: &str) -> Result<FishMap> {
} }
fn count_fishes(fishes: FishMap) -> isize { fn count_fishes(fishes: FishMap) -> isize {
fishes.into_iter().map(|(_, amount)| amount).sum() fishes.values().sum()
} }
fn simulate_fishes(fishes: FishMap) -> FishMap { fn simulate_fishes(fishes: FishMap) -> FishMap {