Brute force day5-2, needs to be better.

This commit is contained in:
Dennis Brentjes 2023-12-06 11:56:09 +01:00
parent 2946a6a212
commit 0837ae6fa0
2 changed files with 16 additions and 3 deletions

View File

@ -82,6 +82,17 @@ impl Almanac {
})
}).min().unwrap()
}
fn interpret_range(self: &mut Self) -> () {
let mut vec:Vec<u32> = 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<u32, AdventError>
pub fn two() -> Result<u32, AdventError>
{
Ok(0)
let mut almanac = read_into::<Almanac>(Path::new("resources/input5.txt".into()))?;
almanac.interpret_range();
Ok(almanac.find_closest())
}

View File

@ -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 }))