diff --git a/aoc2018/src/day05.rs b/aoc2018/src/day05.rs index 9b2c52a..1b6ac4a 100644 --- a/aoc2018/src/day05.rs +++ b/aoc2018/src/day05.rs @@ -14,12 +14,11 @@ pub fn run() -> Result { 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 { - 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 { @@ -32,7 +31,7 @@ fn collapse(input: &str) -> String { match last { Some(elem) => { // 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 last = res.pop(); } else { diff --git a/aoc2019/src/day14.rs b/aoc2019/src/day14.rs index 4462914..5c7fb25 100644 --- a/aoc2019/src/day14.rs +++ b/aoc2019/src/day14.rs @@ -78,7 +78,7 @@ fn get_ore_cost( .with_context(|| format!("couldn't find recipe for {}", material))?; 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 { total += get_ore_cost( elem.name.clone(), diff --git a/aoc2020/src/day07.rs b/aoc2020/src/day07.rs index b846d51..22915af 100644 --- a/aoc2020/src/day07.rs +++ b/aoc2020/src/day07.rs @@ -70,7 +70,7 @@ impl BagRule { all_bags: &HashMap, memoized: &mut HashMap, ) -> bool { - return match memoized.get(&self.color) { + match memoized.get(&self.color) { Some(value) => *value, None => { let value = self.contains.iter().any(|(_, c)| c == color) @@ -85,7 +85,7 @@ impl BagRule { value } - }; + } } fn num_inner_bags(&self, all_bags: &HashMap) -> usize { diff --git a/aoc2020/src/day13.rs b/aoc2020/src/day13.rs index 5fe9974..8a36cb2 100644 --- a/aoc2020/src/day13.rs +++ b/aoc2020/src/day13.rs @@ -91,7 +91,7 @@ fn find_timestamp(input: &str) -> Result { } fn satisfies_constraint(solution: u64, (remainder, divisor): (u64, u64)) -> bool { - ((solution + remainder) % divisor) == 0 + (solution + remainder).is_multiple_of(divisor) } #[cfg(test)] diff --git a/aoc2021/src/day03.rs b/aoc2021/src/day03.rs index a96113c..e4aa948 100644 --- a/aoc2021/src/day03.rs +++ b/aoc2021/src/day03.rs @@ -84,7 +84,7 @@ where 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); numbers.retain(|number| number.chars().nth(pos).unwrap() == digit_of_interest); diff --git a/aoc2022/src/day03.rs b/aoc2022/src/day03.rs index 1270cfa..a58b5dd 100644 --- a/aoc2022/src/day03.rs +++ b/aoc2022/src/day03.rs @@ -84,7 +84,7 @@ impl std::str::FromStr for RucksackSplit { type Err = anyhow::Error; fn from_str(s: &str) -> Result { - if s.len() % 2 != 0 { + if !s.len().is_multiple_of(2) { bail!( "rucksack should contain an even number of items, this one contained {}", s.len() diff --git a/aoc2023/src/day01.rs b/aoc2023/src/day01.rs index 3152fb1..4e0fb86 100644 --- a/aoc2023/src/day01.rs +++ b/aoc2023/src/day01.rs @@ -28,7 +28,7 @@ fn part1(input: &str) -> Result { .sum()) } -fn part2(input: &str) -> Result { +fn part2(_input: &str) -> Result { todo!() }