From 0837ae6fa01baa3ac6001fd4207d42519628e313 Mon Sep 17 00:00:00 2001 From: Dennis Brentjes Date: Wed, 6 Dec 2023 11:56:09 +0100 Subject: [PATCH] Brute force day5-2, needs to be better. --- src/days/day5.rs | 15 ++++++++++++++- src/main.rs | 4 ++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/days/day5.rs b/src/days/day5.rs index bd23bf5..c98e6bf 100644 --- a/src/days/day5.rs +++ b/src/days/day5.rs @@ -82,6 +82,17 @@ impl Almanac { }) }).min().unwrap() } + + fn interpret_range(self: &mut Self) -> () { + let mut vec:Vec = vec![]; + let upper_bound = self.seeds.len() / 2; + for i in 0..upper_bound { + for seed in self.seeds[i*2]..self.seeds[i*2]+self.seeds[i*2+1] { + vec.push(seed); + } + } + self.seeds = vec; + } } enum State { @@ -172,5 +183,7 @@ pub fn one() -> Result pub fn two() -> Result { - Ok(0) + let mut almanac = read_into::(Path::new("resources/input5.txt".into()))?; + almanac.interpret_range(); + Ok(almanac.find_closest()) } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 8b8780b..2ffabfd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,9 +23,9 @@ fn main() -> Result<(), AdventError> { let one_result = one()?; let two_result = two()?; Ok((one_result, two_result)) - }).map(|r: Result<(u32, u32), AdventError>| { + }).enumerate().map(|(index, r): (usize, Result<(u32, u32), AdventError>)| { match r { - Ok((res1, res2)) => println!("1: {} 2: {}", res1, res2), + Ok((res1, res2)) => println!("{}: ({}, {})", index + 1, res1, res2), Err(e) => println!("Error: {}", e.0) }; }).fold((), |acc, _| { acc }))