Simple reformat
This commit is contained in:
parent
58e7eb909e
commit
ce2778a09f
@ -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;
|
||||
|
@ -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()
|
||||
}
|
Loading…
Reference in New Issue
Block a user