mirror of
https://github.com/RussellChamp/advent-of-code-2024-rust.git
synced 2026-10-28 07:52:30 +00:00
make clippy happy
This commit is contained in:
1 parent
a5cec39ee1
commit
636fd0c9c6
3 files changed
+22
-25
No files matched your search
+5
-6
@@ -22,7 +22,7 @@ pub fn part_one(input: &str) -> Option<u32> {
|
||||
// println!("Line {}: abs({} - {}) = {}", i+1, vec_a[i], vec_b[i], diff)
|
||||
}
|
||||
// println!("Total {result}");
|
||||
return Some(result);
|
||||
Some(result)
|
||||
}
|
||||
|
||||
pub fn part_two(input: &str) -> Option<u32> {
|
||||
@@ -41,16 +41,15 @@ pub fn part_two(input: &str) -> Option<u32> {
|
||||
vec_a.sort();
|
||||
vec_b.sort();
|
||||
|
||||
for i in 0..vec_a.len() {
|
||||
let needle = vec_a[i];
|
||||
let found = vec_b.iter().filter(|&&b| b == needle).count() as u32;
|
||||
let similarity = found * needle;
|
||||
for item in &vec_a {
|
||||
let found = vec_b.iter().filter(|&b| b == item).count() as u32;
|
||||
let similarity = found * item;
|
||||
result += similarity;
|
||||
|
||||
// println!("Line {}: {} found {} times = {}, total {}", i + 1, needle, found, similarity, result);
|
||||
}
|
||||
// println!("Total {result}");
|
||||
return Some(result);
|
||||
Some(result)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
+11
-13
@@ -7,10 +7,10 @@ pub fn part_one(input: &str) -> Option<u32> {
|
||||
let values: Vec<_> = line.split(" ").map(|f| f.parse::<u32>().unwrap()).collect();
|
||||
let is_valid = is_valid_report(&values);
|
||||
// println!("Report {} {} valid", line, if is_valid { "is" } else { "is NOT" });
|
||||
if is_valid { return total + 1 } else { return total };
|
||||
if is_valid { total + 1 } else { total }
|
||||
});
|
||||
|
||||
return Some(valid_reports);
|
||||
Some(valid_reports)
|
||||
}
|
||||
|
||||
pub fn part_two(input: &str) -> Option<u32> {
|
||||
@@ -21,10 +21,10 @@ pub fn part_two(input: &str) -> Option<u32> {
|
||||
|
||||
let is_valid = is_any_valid_report(&values);
|
||||
// println!("Report {} {} valid", line, if is_valid { "is" } else { "is NOT" });
|
||||
if is_valid { return total + 1 } else { return total };
|
||||
if is_valid { total + 1 } else { total }
|
||||
});
|
||||
|
||||
return Some(valid_reports);
|
||||
Some(valid_reports)
|
||||
}
|
||||
|
||||
enum Direction {
|
||||
@@ -33,7 +33,7 @@ enum Direction {
|
||||
Decreasing,
|
||||
}
|
||||
|
||||
fn is_valid_report(values: &Vec<u32>) -> bool {
|
||||
fn is_valid_report(values: &[u32]) -> bool {
|
||||
let mut direction = Direction::Unknown;
|
||||
// println!("Checking values {:?}", values);
|
||||
let mut last_report = *values.first().unwrap();
|
||||
@@ -66,10 +66,10 @@ fn is_valid_report(values: &Vec<u32>) -> bool {
|
||||
last_report = report;
|
||||
}
|
||||
|
||||
return true;
|
||||
true
|
||||
}
|
||||
|
||||
fn is_any_valid_report(values: &Vec<u32>) -> bool {
|
||||
fn is_any_valid_report(values: &[u32]) -> bool {
|
||||
if is_valid_report(values) {
|
||||
return true;
|
||||
}
|
||||
@@ -80,20 +80,18 @@ fn is_any_valid_report(values: &Vec<u32>) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
false
|
||||
}
|
||||
|
||||
fn copy_except(values: &Vec<u32>, exclude_idx: usize) -> Vec<u32> {
|
||||
fn copy_except(values: &[u32], exclude_idx: usize) -> Vec<u32> {
|
||||
let mut new_values: Vec<u32> = Vec::new();
|
||||
let mut idx = 0;
|
||||
for value in values {
|
||||
for (idx, value) in values.iter().enumerate() {
|
||||
if idx != exclude_idx {
|
||||
new_values.push(*value);
|
||||
}
|
||||
idx += 1;
|
||||
}
|
||||
// println!("copied new values {:?}", new_values);
|
||||
return new_values;
|
||||
new_values
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
+6
-6
@@ -11,10 +11,10 @@ pub fn part_one(input: &str) -> Option<u32> {
|
||||
let b = b_str.parse::<u32>().unwrap();
|
||||
let product = a * b;
|
||||
|
||||
return total + product;
|
||||
total + product
|
||||
});
|
||||
|
||||
return Some(result);
|
||||
Some(result)
|
||||
}
|
||||
|
||||
pub fn part_two(input: &str) -> Option<u32> {
|
||||
@@ -25,21 +25,21 @@ pub fn part_two(input: &str) -> Option<u32> {
|
||||
// println!("Captures: {command} ({a_str}, {b_str})");
|
||||
|
||||
match command {
|
||||
"do" => return (true, total),
|
||||
"don't" => return (false, total),
|
||||
"do" => (true, total),
|
||||
"don't" => (false, total),
|
||||
"mul" => {
|
||||
if !enabled { return (enabled, total) };
|
||||
|
||||
let a = a_str.parse::<u32>().unwrap();
|
||||
let b = b_str.parse::<u32>().unwrap();
|
||||
let product = a * b;
|
||||
return (enabled, total + product)
|
||||
(enabled, total + product)
|
||||
},
|
||||
_ => panic!("Could not match command {command}"),
|
||||
}
|
||||
});
|
||||
|
||||
return Some(result);
|
||||
Some(result)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in new issue
Block a user