summaryrefslogtreecommitdiff
path: root/2021/rust/day01
diff options
context:
space:
mode:
authorcos <cos>2021-12-08 21:53:26 +0100
committercos <cos>2021-12-08 21:53:26 +0100
commit1d39665c5ae23ddb3c5648d4844d15255d40b566 (patch)
tree2dab22b8de29750bc5792fd51d6972ecdd896f85 /2021/rust/day01
parentf0b8e240a7e1dcc79c3f2109c6365dbbf7c67b46 (diff)
downloadadventofcode-1d39665c5ae23ddb3c5648d4844d15255d40b566.zip
Minor simplification to 2021day01
Diffstat (limited to '2021/rust/day01')
-rw-r--r--2021/rust/day01/src/main.rs8
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> {