day07: Changes for part 2

Now that we have the sizes of the directories in a list, it's quite easy
to work with them to get part 2 using Iterator functions.
This commit is contained in:
MasterofJOKers 2022-12-20 00:48:04 +01:00
parent 2620d59a8f
commit bc3599fff0
1 changed files with 4 additions and 3 deletions

View File

@ -153,8 +153,9 @@ fn main() -> Result<(), Box<dyn error::Error>> {
// compute sizes
let sizes = fs_tree.get_dir_sizes();
println!("{}", sizes.iter().filter(|x| **x < 100000).sum::<u32>());
println!("Hello, world!");
let full_space = 70000000;
let free_space = full_space - sizes[sizes.len() - 1];
let needed_space = 30000000 - free_space;
println!("{}", sizes.iter().filter(|x| **x > needed_space).min().unwrap());
Ok(())
}