chore: fmt + clippy

This commit is contained in:
Xavier Morel
2024-11-14 15:36:19 +01:00
parent 5eba391ebe
commit e243ca9498
3 changed files with 58 additions and 96 deletions

View File

@@ -1,10 +1,7 @@
advent_of_code::solution!(3);
fn parse_line(input: &str) -> [u32; 3] {
let nb: Result<Vec<u32>, _> = input
.split_whitespace()
.map(str::parse)
.collect();
let nb: Result<Vec<u32>, _> = input.split_whitespace().map(str::parse).collect();
if let Ok(nb) = nb {
if nb.len() == 3 {
return [nb[0], nb[1], nb[2]];
@@ -26,7 +23,7 @@ fn parse_input(input: &str) -> Vec<[u32; 3]> {
fn parse_input_p2(input: &str) -> Vec<[u32; 3]> {
parse_input(input)
.chunks(3)
.map(|c| {
.flat_map(|c| {
let v = c.to_vec();
if v.len() != 3 {
println!("{:?}", v);
@@ -34,44 +31,23 @@ fn parse_input_p2(input: &str) -> Vec<[u32; 3]> {
}
let vs = [v[0], v[1], v[2]];
// LAAAAAAZY... Could have transposed
let [
[ta1, tb1, tc1],
[ta2, tb2, tc2],
[ta3, tb3, tc3],
] = vs;
[
[ta1, ta2, ta3],
[tb1, tb2, tb3],
[tc1, tc2, tc3],
].to_vec()
let [[ta1, tb1, tc1], [ta2, tb2, tc2], [ta3, tb3, tc3]] = vs;
[[ta1, ta2, ta3], [tb1, tb2, tb3], [tc1, tc2, tc3]].to_vec()
})
.flatten()
.collect()
}
fn is_valid(triangle: &[u32; 3]) -> bool {
let &[a, b, c] = triangle;
(a + b) > c
&& (b + c) > a
&& (c + a) > b
(a + b) > c && (b + c) > a && (c + a) > b
}
pub fn part_one(input: &str) -> Option<u32> {
Some(
parse_input(input)
.into_iter()
.filter(is_valid)
.count() as u32
)
Some(parse_input(input).into_iter().filter(is_valid).count() as u32)
}
pub fn part_two(input: &str) -> Option<u32> {
Some(
parse_input_p2(input)
.into_iter()
.filter(is_valid)
.count() as u32
)
Some(parse_input_p2(input).into_iter().filter(is_valid).count() as u32)
}
#[cfg(test)]