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:
parent
edd8bdfa71
commit
11907cf8b5
1 changed files with 1 additions and 9 deletions
|
@ -42,14 +42,6 @@ pub fn unscramble(line: &str) -> LineResult {
|
|||
|
||||
LineResult {
|
||||
unique_digits: digits.iter().filter(|d| [1, 4, 7, 8].contains(d)).count(),
|
||||
number: digits
|
||||
.iter()
|
||||
.rev()
|
||||
.scan(1, |mul, &d| {
|
||||
let ret = Some(d * *mul);
|
||||
*mul *= 10;
|
||||
ret
|
||||
})
|
||||
.sum(),
|
||||
number: digits.iter().fold(0, |acc, d| acc * 10 + d),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue