From a7c32b213fc2bdf736508c93cd629c998c4c7897 Mon Sep 17 00:00:00 2001 From: Keenan Tims Date: Mon, 1 Dec 2025 17:15:54 -0800 Subject: [PATCH] clippies --- src/day1.rs | 4 ++-- src/day2.rs | 8 ++++---- src/day3.rs | 20 +++++++++----------- src/day4.rs | 4 ++-- src/day6.rs | 2 +- 5 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/day1.rs b/src/day1.rs index 1e7dafe..d8f8e05 100644 --- a/src/day1.rs +++ b/src/day1.rs @@ -20,12 +20,12 @@ fn parse(input: &[u8]) -> Vec { } #[aoc(day1, part1)] -fn part1(input: &Vec) -> u64 { +fn part1(input: &[u64]) -> u64 { *input.iter().max().unwrap() } #[aoc(day1, part2)] -fn part2(input: &Vec) -> u64 { +fn part2(input: &[u64]) -> u64 { input.iter().sorted().rev().take(3).sum::() } diff --git a/src/day2.rs b/src/day2.rs index 6737f2b..ca127b2 100644 --- a/src/day2.rs +++ b/src/day2.rs @@ -93,7 +93,7 @@ pub struct Move { impl FromStr for Move { type Err = Box; fn from_str(value: &str) -> Result { - let (theirs, ours) = value.split_once(&" ").ok_or("Unable to split")?; + let (theirs, ours) = value.split_once(" ").ok_or("Unable to split")?; Ok(Move { ours: ours.parse()?, theirs: theirs.parse()?, @@ -115,7 +115,7 @@ pub struct MoveGoal { impl FromStr for MoveGoal { type Err = Box; fn from_str(s: &str) -> Result { - let (theirs, goal) = s.split_once(&" ").ok_or("Unable to split")?; + let (theirs, goal) = s.split_once(" ").ok_or("Unable to split")?; Ok(MoveGoal { theirs: theirs.parse()?, goal: goal.parse()?, @@ -142,12 +142,12 @@ fn parse_part2(input: &[u8]) -> Vec { } #[aoc(day2, part1)] -fn part1(input: &Vec) -> u64 { +fn part1(input: &[Move]) -> u64 { input.iter().map(|m| m.score()).sum() } #[aoc(day2, part2)] -fn part2(input: &Vec) -> u64 { +fn part2(input: &[MoveGoal]) -> u64 { input.iter().map(|mg| mg.get_move().score()).sum() } diff --git a/src/day3.rs b/src/day3.rs index ac6523a..6a76e40 100644 --- a/src/day3.rs +++ b/src/day3.rs @@ -8,9 +8,7 @@ struct Rucksack { impl From<&[u8]> for Rucksack { fn from(s: &[u8]) -> Self { - Self { - items: s.iter().cloned().collect(), - } + Self { items: s.to_vec() } } } @@ -18,8 +16,8 @@ impl Display for Rucksack { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.write_fmt(format_args!( "{}{}", - String::from_utf8_lossy(&self.compartments()[0]), - String::from_utf8_lossy(&self.compartments()[1]) + String::from_utf8_lossy(self.compartments()[0]), + String::from_utf8_lossy(self.compartments()[1]) )) } } @@ -31,13 +29,13 @@ impl Rucksack { } fn common(&self) -> u8 { for item in self.compartments()[0] { - if self.compartments()[1].contains(&item) { + if self.compartments()[1].contains(item) { return *item; } } panic!("Common item not found"); } - fn common_with<'a>(&self, other: &[u8]) -> impl Iterator { + fn common_with(&self, other: &[u8]) -> impl Iterator { self.compartments() .into_iter() .flatten() @@ -47,9 +45,9 @@ impl Rucksack { } fn priority(c: u8) -> u8 { - if c >= b'A' && c <= b'Z' { + if c.is_ascii_uppercase() { c - b'A' + 27 - } else if c >= b'a' && c <= b'z' { + } else if c.is_ascii_lowercase() { c - b'a' + 1 } else { panic!("Invalid item {c}") @@ -62,12 +60,12 @@ fn parse(input: &[u8]) -> Vec { } #[aoc(day3, part1)] -fn part1(input: &Vec) -> u64 { +fn part1(input: &[Rucksack]) -> u64 { input.iter().map(|sack| priority(sack.common()) as u64).sum() } #[aoc(day3, part2)] -fn part2(input: &Vec) -> u64 { +fn part2(input: &[Rucksack]) -> u64 { let mut total = 0u64; for sacks in input.chunks(3) { let commons_1 = sacks[0].common_with(&sacks[1].items).unique().collect_vec(); diff --git a/src/day4.rs b/src/day4.rs index f716478..62ba1cd 100644 --- a/src/day4.rs +++ b/src/day4.rs @@ -35,12 +35,12 @@ fn parse(input: &str) -> Vec { } #[aoc(day4, part1)] -fn part1(input: &Vec) -> u64 { +fn part1(input: &[Pair]) -> u64 { input.iter().filter(|p| p.fully_contained()).count() as u64 } #[aoc(day4, part2)] -fn part2(input: &Vec) -> u64 { +fn part2(input: &[Pair]) -> u64 { input.iter().filter(|p| p.overlaps()).count() as u64 } diff --git a/src/day6.rs b/src/day6.rs index 37fa642..4db61e3 100644 --- a/src/day6.rs +++ b/src/day6.rs @@ -42,7 +42,7 @@ fn part2(input: &[u8]) -> u64 { return None; } } - return Some(i + 14); + Some(i + 14) }) .unwrap() as u64 }