fix clippy lints
This commit is contained in:
parent
7c90bccfa8
commit
02bc7875f6
7 changed files with 12 additions and 13 deletions
|
|
@ -14,12 +14,11 @@ pub fn run() -> Result<String> {
|
|||
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 {
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ impl BagRule {
|
|||
all_bags: &HashMap<String, BagRule>,
|
||||
memoized: &mut HashMap<String, bool>,
|
||||
) -> 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<String, BagRule>) -> usize {
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ fn find_timestamp(input: &str) -> Result<u64> {
|
|||
}
|
||||
|
||||
fn satisfies_constraint(solution: u64, (remainder, divisor): (u64, u64)) -> bool {
|
||||
((solution + remainder) % divisor) == 0
|
||||
(solution + remainder).is_multiple_of(divisor)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ impl std::str::FromStr for RucksackSplit {
|
|||
type Err = anyhow::Error;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
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()
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ fn part1(input: &str) -> Result<u64> {
|
|||
.sum())
|
||||
}
|
||||
|
||||
fn part2(input: &str) -> Result<u64> {
|
||||
fn part2(_input: &str) -> Result<u64> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue