1
0

Simple reformat

This commit is contained in:
Florent DENEF 2023-03-02 10:33:35 +01:00
parent 58e7eb909e
commit ce2778a09f
2 changed files with 8 additions and 15 deletions

View File

@ -1,8 +1,7 @@
extern crate core;
pub mod prob1;
pub mod prob2;
pub mod prob3;
pub mod prob4;
pub mod prob5;
pub mod prob6;
pub mod prob6;
pub mod prob7;

View File

@ -11,37 +11,31 @@ pub fn complete_overlap(first_pair: &[u32], second_pair: &[u32]) -> bool {
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.")
.unwrap_or_else(|err| panic!("Please provide a text file as an argument: {err}"))
.lines()
.map(|line| {
let tmp = line.split(',').collect::<Vec<&str>>();
let first_pair = tmp
.first()
.expect("First character error")
.unwrap_or_else(|| panic!("First character error"))
.split('-')
.map(|first_split| {
first_split
.parse::<u32>()
.expect("Parsing number in first pair failed")
.unwrap_or_else(|err| panic!("Parsing number in first pair failed: {err}"))
})
.collect::<Vec<u32>>();
let second_pair = tmp
.last()
.expect("First character error")
.unwrap_or_else(|| panic!("First character error"))
.split('-')
.map(|first_split| {
first_split
.parse::<u32>()
.expect("Parsing number in first pair failed")
.unwrap_or_else(|err| panic!("Parsing number in first pair failed: {err}"))
})
.collect::<Vec<u32>>();
if unary_operator(&first_pair, &second_pair) {
1
} else {
0
}
i32::from(unary_operator(&first_pair, &second_pair))
})
.collect::<Vec<i32>>()
.iter()
.sum()
}