Day 7, puzzle 2

This commit is contained in:
jazzpi 2022-12-14 13:32:05 +01:00
parent bedf4a790a
commit 1156bc2e75
1 changed files with 26 additions and 0 deletions

26
src/bin/d7p2.rs Normal file
View File

@ -0,0 +1,26 @@
use aoc22::{day7, util};
const TOTAL_SPACE: usize = 70000000;
const REQUIRED_SPACE: usize = 30000000;
pub fn main() {
let root = day7::parse_cmdline(&util::parse_input());
let r = &*root.borrow();
let free_space = TOTAL_SPACE - r.size();
assert!(free_space < REQUIRED_SPACE);
let required_deletion = REQUIRED_SPACE - free_space;
let mut min_sufficient = usize::MAX;
for child in root.borrow().all_children() {
let c = &*child.borrow();
if let day7::Node::Dir { .. } = c {
let size = c.size();
if size >= required_deletion && size <= min_sufficient {
min_sufficient = size;
}
}
}
println!("Size of min sufficient dir is {}", min_sufficient);
}