Skip to content

Commit 8e04aa7

Browse files
committed
Rust fmt and clippy fixes
1 parent 87f06da commit 8e04aa7

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

2024/Rust/aoc2024/src/commands/day1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub fn handle(input_file: std::path::PathBuf, part_number: u8) -> Result<(), io:
5050
}
5151
}
5252

53-
pub fn part_1(left_ids: &mut Vec<u32>, right_ids: &mut Vec<u32>) -> Result<(), io::Error> {
53+
pub fn part_1(left_ids: &mut [u32], right_ids: &mut [u32]) -> Result<(), io::Error> {
5454
left_ids.sort();
5555
right_ids.sort();
5656
let mut diff: u32 = 0;

2024/Rust/aoc2024/src/commands/day2.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use nom::{
22
character::complete::{digit1, newline, space1},
3-
multi::separated_list1,
43
combinator::map_res,
4+
multi::separated_list1,
55
IResult,
66
};
7-
use std::{fs::read_to_string, iter::zip};
87
use std::io;
8+
use std::{fs::read_to_string, iter::zip};
99

1010
#[derive(Debug, PartialEq)]
1111
pub struct Report {
@@ -31,7 +31,10 @@ pub fn handle(input_file: std::path::PathBuf, part_number: u8) -> Result<(), io:
3131
match part_number {
3232
1 => part_1(&contents),
3333
2 => part_2(&contents),
34-
_ => Err(io::Error::new(io::ErrorKind::InvalidInput, "Invalid part number")),
34+
_ => Err(io::Error::new(
35+
io::ErrorKind::InvalidInput,
36+
"Invalid part number",
37+
)),
3538
}
3639
}
3740

@@ -59,7 +62,7 @@ impl LevelsValidation for Report {
5962

6063
for (current, next) in zip(to_check, &to_check[1..]) {
6164
let diff = next - current;
62-
if diff < 1 || diff > 3 {
65+
if !(1..=3).contains(&diff) {
6366
return false;
6467
}
6568
}
@@ -79,7 +82,9 @@ impl LevelsValidation for Report {
7982
for i in 0..self.levels.len() {
8083
let mut test_levels = self.levels.clone();
8184
test_levels.remove(i);
82-
let report = Report { levels: test_levels };
85+
let report = Report {
86+
levels: test_levels,
87+
};
8388
if report.levels_are_valid() {
8489
return true;
8590
}
@@ -98,7 +103,10 @@ pub fn part_1(input: &str) -> Result<(), io::Error> {
98103

99104
pub fn part_2(input: &str) -> Result<(), io::Error> {
100105
let (_, reports) = parse_reports(input).unwrap();
101-
let valid_count = reports.iter().filter(|r| r.problem_dampened_is_valid()).count();
106+
let valid_count = reports
107+
.iter()
108+
.filter(|r| r.problem_dampened_is_valid())
109+
.count();
102110
println!("{}", valid_count);
103111
Ok(())
104112
}

0 commit comments

Comments
 (0)