diff options
-rw-r--r-- | 2021/rust/day01/src/main.rs | 8 |
1 files changed, 2 insertions, 6 deletions
diff --git a/2021/rust/day01/src/main.rs b/2021/rust/day01/src/main.rs index 559f98c..d0ac932 100644 --- a/2021/rust/day01/src/main.rs +++ b/2021/rust/day01/src/main.rs @@ -32,7 +32,7 @@ enum Change { } fn count_increases<'a, I: IntoIterator<Item = &'a usize>>(values: I) -> usize { - let changes: Vec<Change> = values.into_iter().scan(None, |state, val| { + values.into_iter().scan(None, |state, val| { let next = match state { None => Change::NoPrevVal, Some(prev) if val < *prev => Change::Decreased, @@ -42,11 +42,7 @@ fn count_increases<'a, I: IntoIterator<Item = &'a usize>>(values: I) -> usize { }; *state = Some(val); Some(next) - }).collect(); - - changes.iter().fold(0, |count, change| - if *change == Change::Increased { count + 1 } else { count } - ) + }).filter(|change| change == &Change::Increased).count() } fn part1<'a, I: IntoIterator<Item = &'a usize>>(input: I) -> Result<usize> { |