From 340b207f812979d74d6d4b15c43c5cee43aacdf3 Mon Sep 17 00:00:00 2001 From: pjht Date: Wed, 7 Dec 2022 13:22:59 -0600 Subject: [PATCH] Clean up handling of root node --- src/day07.rs | 32 +------------------------------- 1 file changed, 1 insertion(+), 31 deletions(-) diff --git a/src/day07.rs b/src/day07.rs index 976c4a0..584d914 100644 --- a/src/day07.rs +++ b/src/day07.rs @@ -23,14 +23,6 @@ impl DirectoryEntry { None } } - - fn as_dir(&self) -> Option<&String> { - if let Self::Dir(v) = self { - Some(v) - } else { - None - } - } } #[derive(Copy, Clone, Debug)] @@ -58,16 +50,6 @@ enum CliOperation { Ls(Vec), } -impl CliOperation { - fn as_ls(&self) -> Option<&Vec> { - if let Self::Ls(v) = self { - Some(v) - } else { - None - } - } -} - #[aoc_generator(day7)] fn input_generator(input: &str) -> Vec { let mut lines = input.lines().peekable(); @@ -95,19 +77,7 @@ fn compute_dir_sizes(input: &[CliOperation]) -> Tree<(usize, usize)> { } let mut tree = Tree::new(); let mut current_node = tree - .insert( - Node::new(( - input[1] - .as_ls() - .unwrap() - .iter() - .filter_map(DirectoryEntry::as_file) - .map(|file| file.size) - .sum::(), - 0, - )), - InsertBehavior::AsRoot, - ) + .insert(Node::new((0, 0)), InsertBehavior::AsRoot) .unwrap(); for op in input { match op {