2021 day8/rust: prettify calculation of output number

Now that `digits` is a fixed-size array, both methods get unrolled the
same and there is no performance difference.
This commit is contained in:
Xiretza 2021-12-09 18:06:40 +01:00
parent edd8bdfa71
commit 11907cf8b5

View file

@ -42,14 +42,6 @@ pub fn unscramble(line: &str) -> LineResult {
LineResult { LineResult {
unique_digits: digits.iter().filter(|d| [1, 4, 7, 8].contains(d)).count(), unique_digits: digits.iter().filter(|d| [1, 4, 7, 8].contains(d)).count(),
number: digits number: digits.iter().fold(0, |acc, d| acc * 10 + d),
.iter()
.rev()
.scan(1, |mul, &d| {
let ret = Some(d * *mul);
*mul *= 10;
ret
})
.sum(),
} }
} }