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)]
|
#[aoc(day7, part1)]
|
||||||
fn solve_part1(input: &[CliOperation]) -> usize {
|
fn solve_part1(input: &[CliOperation]) -> usize {
|
||||||
let tree = compute_dir_sizes(input);
|
let tree = compute_dir_sizes(input);
|
||||||
let mut sum = 0;
|
tree.traverse_post_order(tree.root_node_id().unwrap())
|
||||||
for node in tree
|
|
||||||
.traverse_post_order(tree.root_node_id().unwrap())
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
{
|
.map(|node| node.data().1)
|
||||||
if node.data().1 <= 100000 {
|
.filter(|&size| size <= 100_000)
|
||||||
sum += node.data().1;
|
.sum()
|
||||||
}
|
|
||||||
}
|
|
||||||
sum
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[aoc(day7, part2)]
|
#[aoc(day7, part2)]
|
||||||
|
Loading…
Reference in New Issue
Block a user