-
Notifications
You must be signed in to change notification settings - Fork 525
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sum-of-multiples: update "deep dive" (#1915)
- Loading branch information
1 parent
648df80
commit 7946b9b
Showing
3 changed files
with
24 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions
10
exercises/practice/sum-of-multiples/.approaches/from-factors/snippet.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
pub fn sum_of_multiples_from_factors(limit: u32, factors: &[u32]) -> u32 { | ||
let mut multiples: Vec<_> = factors.iter() | ||
factors | ||
.iter() | ||
.filter(|&&factor| factor != 0) | ||
.flat_map(|&factor| (factor..limit).step_by(factor as usize)) | ||
.collect(); | ||
multiples.sort(); | ||
multiples.dedup(); | ||
multiples.iter().sum() | ||
.collect::<HashSet<_>>() | ||
.iter() | ||
.sum() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters