Rewrite part 2 to use iterators

This commit is contained in:
pjht 2022-12-07 13:25:23 -06:00
parent 340b207f81
commit 0b9a1061a0

View File

@ -121,16 +121,11 @@ fn compute_dir_sizes(input: &[CliOperation]) -> Tree<(usize, usize)> {
#[aoc(day7, part1)]
fn solve_part1(input: &[CliOperation]) -> usize {
let tree = compute_dir_sizes(input);
let mut sum = 0;
for node in tree
.traverse_post_order(tree.root_node_id().unwrap())
tree.traverse_post_order(tree.root_node_id().unwrap())
.unwrap()
{
if node.data().1 <= 100000 {
sum += node.data().1;
}
}
sum
.map(|node| node.data().1)
.filter(|&size| size <= 100_000)
.sum()
}
#[aoc(day7, part2)]