fix clippy lints

This commit is contained in:
Antoine Martin 2025-12-01 13:59:04 +01:00
parent 7c90bccfa8
commit 02bc7875f6
7 changed files with 12 additions and 13 deletions

View file

@ -14,12 +14,11 @@ pub fn run() -> Result<String> {
Ok(res) Ok(res)
} }
fn same_type(a: char, b: char) -> bool {
a.to_ascii_lowercase() == b.to_ascii_lowercase()
}
fn remove_type(input: &str, c: char) -> String { fn remove_type(input: &str, c: char) -> String {
input.chars().filter(|ch| !same_type(c, *ch)).collect() input
.chars()
.filter(|ch| !c.eq_ignore_ascii_case(ch))
.collect()
} }
fn collapse(input: &str) -> String { fn collapse(input: &str) -> String {
@ -32,7 +31,7 @@ fn collapse(input: &str) -> String {
match last { match last {
Some(elem) => { Some(elem) => {
// if same type but different polarity // if same type but different polarity
if same_type(elem, next) && elem != next { if elem.eq_ignore_ascii_case(&next) && elem != next {
// drop both elem and next // drop both elem and next
last = res.pop(); last = res.pop();
} else { } else {

View file

@ -78,7 +78,7 @@ fn get_ore_cost(
.with_context(|| format!("couldn't find recipe for {}", material))?; .with_context(|| format!("couldn't find recipe for {}", material))?;
let needed = quantity - in_stock; let needed = quantity - in_stock;
let num_reactions = (needed + recipe.produced - 1) / recipe.produced; let num_reactions = needed.div_ceil(recipe.produced);
for elem in &recipe.elems { for elem in &recipe.elems {
total += get_ore_cost( total += get_ore_cost(
elem.name.clone(), elem.name.clone(),

View file

@ -70,7 +70,7 @@ impl BagRule {
all_bags: &HashMap<String, BagRule>, all_bags: &HashMap<String, BagRule>,
memoized: &mut HashMap<String, bool>, memoized: &mut HashMap<String, bool>,
) -> bool { ) -> bool {
return match memoized.get(&self.color) { match memoized.get(&self.color) {
Some(value) => *value, Some(value) => *value,
None => { None => {
let value = self.contains.iter().any(|(_, c)| c == color) let value = self.contains.iter().any(|(_, c)| c == color)
@ -85,7 +85,7 @@ impl BagRule {
value value
} }
}; }
} }
fn num_inner_bags(&self, all_bags: &HashMap<String, BagRule>) -> usize { fn num_inner_bags(&self, all_bags: &HashMap<String, BagRule>) -> usize {

View file

@ -91,7 +91,7 @@ fn find_timestamp(input: &str) -> Result<u64> {
} }
fn satisfies_constraint(solution: u64, (remainder, divisor): (u64, u64)) -> bool { fn satisfies_constraint(solution: u64, (remainder, divisor): (u64, u64)) -> bool {
((solution + remainder) % divisor) == 0 (solution + remainder).is_multiple_of(divisor)
} }
#[cfg(test)] #[cfg(test)]

View file

@ -84,7 +84,7 @@ where
break; break;
} }
let one_is_more_common = count_ones(&numbers, pos) >= ((numbers.len() + 1) / 2); let one_is_more_common = count_ones(&numbers, pos) >= numbers.len().div_ceil(2);
let digit_of_interest = strat(one_is_more_common); let digit_of_interest = strat(one_is_more_common);
numbers.retain(|number| number.chars().nth(pos).unwrap() == digit_of_interest); numbers.retain(|number| number.chars().nth(pos).unwrap() == digit_of_interest);

View file

@ -84,7 +84,7 @@ impl std::str::FromStr for RucksackSplit {
type Err = anyhow::Error; type Err = anyhow::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
if s.len() % 2 != 0 { if !s.len().is_multiple_of(2) {
bail!( bail!(
"rucksack should contain an even number of items, this one contained {}", "rucksack should contain an even number of items, this one contained {}",
s.len() s.len()

View file

@ -28,7 +28,7 @@ fn part1(input: &str) -> Result<u64> {
.sum()) .sum())
} }
fn part2(input: &str) -> Result<u64> { fn part2(_input: &str) -> Result<u64> {
todo!() todo!()
} }