From 88549528a890816a3bfae5214764619b1037896b Mon Sep 17 00:00:00 2001 From: Florent DENEF Date: Fri, 9 Dec 2022 16:15:13 +0100 Subject: [PATCH] WIP making it work. --- src/main.rs | 5 +++++ src/prob4/mod.rs | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/src/main.rs b/src/main.rs index 61b2c22..88bfc5e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,4 +28,9 @@ fn main() { let max_part1 = prob4::solve(file_path, &prob4::mutual_inclusion); println!("Solution for problem 4 part 1: {max_part1}"); } + { + let file_path = "prob4_part1.txt"; + let max_part1 = prob4::solve(file_path, &prob4::complete_overlap); + println!("Solution for problem 4 part 2: {max_part1}"); + } } diff --git a/src/prob4/mod.rs b/src/prob4/mod.rs index 6219ab8..491afa2 100644 --- a/src/prob4/mod.rs +++ b/src/prob4/mod.rs @@ -3,6 +3,10 @@ pub fn mutual_inclusion(first_pair: &[u32], second_pair: &[u32]) -> bool { || (second_pair[0] <= first_pair[0] && second_pair[1] >= first_pair[1]) } +pub fn complete_overlap(first_pair: &[u32], second_pair: &[u32]) -> bool { + (second_pair[0] <= first_pair[0] && first_pair[0] <= second_pair[1]) || (second_pair[0] <= first_pair[1] && first_pair[1] <= second_pair[1]) +} + 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.")