Day 7, puzzle 2
This commit is contained in:
parent
bedf4a790a
commit
1156bc2e75
|
@ -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);
|
||||
}
|
Loading…
Reference in New Issue