Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mflinn-broad committed Dec 10, 2021
1 parent dc65f69 commit 150fc37
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/days/day10.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn part_2(input: &Vec<Vec<char>>) -> usize {
// remove corrupted and complete lines
let completion_scores: Vec<usize> = input
.iter()
.fold(Vec::new(),|mut completions, line| {
.map(|line| {
let mut stack: Vec<char> = Vec::new();
for symbol in line {
match symbol {
Expand All @@ -64,18 +64,17 @@ fn part_2(input: &Vec<Vec<char>>) -> 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,
Expand Down

0 comments on commit 150fc37

Please sign in to comment.