From ce2778a09f0ad2abdce33b7bb68d481d81067a85 Mon Sep 17 00:00:00 2001 From: Florent DENEF Date: Thu, 2 Mar 2023 10:33:35 +0100 Subject: [PATCH] Simple reformat --- src/lib.rs | 5 ++--- src/prob4/mod.rs | 18 ++++++------------ 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 5762b5f..ed07268 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; \ No newline at end of file +pub mod prob6; +pub mod prob7; diff --git a/src/prob4/mod.rs b/src/prob4/mod.rs index 35e3b3e..f1ea45c 100644 --- a/src/prob4/mod.rs +++ b/src/prob4/mod.rs @@ -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::>(); let first_pair = tmp .first() - .expect("First character error") + .unwrap_or_else(|| panic!("First character error")) .split('-') .map(|first_split| { first_split .parse::() - .expect("Parsing number in first pair failed") + .unwrap_or_else(|err| panic!("Parsing number in first pair failed: {err}")) }) .collect::>(); let second_pair = tmp .last() - .expect("First character error") + .unwrap_or_else(|| panic!("First character error")) .split('-') .map(|first_split| { first_split .parse::() - .expect("Parsing number in first pair failed") + .unwrap_or_else(|err| panic!("Parsing number in first pair failed: {err}")) }) .collect::>(); - if unary_operator(&first_pair, &second_pair) { - 1 - } else { - 0 - } + i32::from(unary_operator(&first_pair, &second_pair)) }) - .collect::>() - .iter() .sum() } \ No newline at end of file