Rewrite part 2 to use iterators
This commit is contained in:
parent
340b207f81
commit
0b9a1061a0
13
src/day07.rs
13
src/day07.rs
@ -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)]
|
||||
|
Loading…
Reference in New Issue
Block a user