1
0
Fork 0

Next star gotten

This commit is contained in:
Vivianne 2022-12-10 15:26:17 -08:00
parent 62edf7f697
commit b1f467d62b

View file

@ -301,4 +301,34 @@ fn part1(lines: &[String]) {
.sum::<usize>());
}
fn part2(_lines: &[String]) {}
fn part2(lines: &[String]) {
let mut state = State::new();
lines
.iter()
.flat_map(|l| line(l))
.for_each(|(_, l)| state.process(l).unwrap());
let full_size = state.filesystem.calculate_size();
dbg!(full_size);
const AVAILABLE_SPACE: usize = 70_000_000;
const DESIRED_AVAILABLE_SPACE: usize = 30_000_000;
const MAX_USED: usize = AVAILABLE_SPACE - DESIRED_AVAILABLE_SPACE;
let over_by = full_size - MAX_USED;
println!(
"{}",
state
.filesystem
.into_iter()
.filter(|f| f.is_dir()
&& match f.size {
Some(s) => s >= over_by,
_ => false,
})
.min_by(|a, b| a.size.cmp(&b.size))
.expect("Expect a minimum")
);
}