diff --git a/src/days/day10.rs b/src/days/day10.rs index e0a194c..05a40af 100644 --- a/src/days/day10.rs +++ b/src/days/day10.rs @@ -52,7 +52,7 @@ fn part_2(input: &Vec>) -> usize { // remove corrupted and complete lines let completion_scores: Vec = input .iter() - .fold(Vec::new(),|mut completions, line| { + .map(|line| { let mut stack: Vec = Vec::new(); for symbol in line { match symbol { @@ -64,18 +64,17 @@ fn part_2(input: &Vec>) -> usize { stack.pop(); } _ => { - return completions; + return Vec::new(); } } } - if stack.len() == 0 { - completions + if stack.is_empty(){ + Vec::new() } else { - completions.push(stack); - completions + stack } }) - .iter() + .filter(|completion| !completion.is_empty()) .map(|completion| { completion.iter().rev().fold(0, |score, symbol| match symbol { ')' => (score * 5) + 1,