1
0

Commit edited manually.

This commit is contained in:
Florent DENEF 2022-12-09 16:10:13 +01:00
parent 32744e2ed2
commit e32002c0c5

View File

@ -1,9 +1,9 @@
fn mutual_inclusion(first_pair: &[u32], second_pair: &[u32]) -> bool {
pub fn mutual_inclusion(first_pair: &[u32], second_pair: &[u32]) -> bool {
(first_pair[0] <= second_pair[0] && first_pair[1] >= second_pair[1])
|| (second_pair[0] <= first_pair[0] && second_pair[1] >= first_pair[1])
}
pub fn solve_part1(file_path: &str) -> i32 {
pub fn solve(file_path: &str, unary_operator: &dyn Fn(&[u32], &[u32]) -> bool) -> i32 {
std::fs::read_to_string(file_path)
.expect("Please provide a text file as an argument.")
.lines()
@ -29,7 +29,7 @@ pub fn solve_part1(file_path: &str) -> i32 {
.expect("Parsing number in first pair failed")
})
.collect::<Vec<u32>>();
if mutual_inclusion(&first_pair, &second_pair) {
if unary_operator(&first_pair, &second_pair) {
1
} else {
0
@ -38,4 +38,4 @@ pub fn solve_part1(file_path: &str) -> i32 {
.collect::<Vec<i32>>()
.iter()
.sum()
}
}