diff --git a/2022/src/days/day7.rs b/2022/src/days/day7.rs index fe76991..744b084 100644 --- a/2022/src/days/day7.rs +++ b/2022/src/days/day7.rs @@ -1,8 +1,8 @@ use anyhow::{anyhow, Result}; -use std::fs; use std::collections::BTreeMap; +use std::fs; -#[derive(Debug,Default)] +#[derive(Debug, Default)] struct Dir { name: String, files: Vec, @@ -68,7 +68,7 @@ fn part_two_sizes<'a>(dir: &'a Dir, needed: u32) -> Option<(u32, &'a str)> { for (key, val) in map.iter() { if *key >= needed { - return Some((*key, val)) + return Some((*key, val)); } } @@ -76,7 +76,10 @@ fn part_two_sizes<'a>(dir: &'a Dir, needed: u32) -> Option<(u32, &'a str)> { } fn part_two_recurse<'a>(map: &mut BTreeMap, dir: &'a Dir) { - map.insert((dir.total_size as u32).try_into().unwrap(), dir.name.as_str()); + map.insert( + (dir.total_size as u32).try_into().unwrap(), + dir.name.as_str(), + ); for subdir in dir.directories.iter() { part_two_recurse(map, subdir); } @@ -165,10 +168,18 @@ pub fn run() -> Result<()> { let min_free_space = 30000000; let free_space = total_disk - root.total_size as u32; let needed_space = min_free_space - free_space; - println!("total size used {} free {} needed {}", root.total_size, free_space, needed_space); + println!( + "total size used {} free {} needed {}", + root.total_size, free_space, needed_space + ); if let Some((rm_space, rm_name)) = part_two_sizes(&root, needed_space) { - println!("part two: should delete {} to reclaim {} total free space {}", rm_name, rm_space, free_space + rm_space); + println!( + "part two: should delete {} to reclaim {} total free space {}", + rm_name, + rm_space, + free_space + rm_space + ); } else { println!("could not find part 2"); }