-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3e456e2
commit bbc4026
Showing
5 changed files
with
28 additions
and
0 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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
Project Euler Problem 111 | ||
*/ | ||
use std::iter::zip; | ||
|
||
use crate::include::primes::primes_until; | ||
use crate::include::utils::Answer; | ||
|
||
pub fn p0111() -> Answer { | ||
let ten_9: u64 = 10_u64.pow(9); | ||
let ten_10: u64 = 10_u64.pow(10); | ||
let primes_int: Vec<u64> = primes_until::<u64>(ten_10).filter(|x| *x > ten_9).collect(); | ||
let primes_str: Vec<String> = primes_int.iter().map(|p| (*p).to_string()).collect(); | ||
let mut answer: u64 = 0; | ||
for digit in 0..=9 { | ||
let primes_counts: Vec<usize> = primes_str.iter().map(|s| (*s).bytes().filter(|b| *b == digit + b'0').count()).collect(); | ||
let n: usize = primes_counts.iter().map(|x| *x).max().unwrap(); | ||
Check warning Code scanning / clippy you are using an explicit closure for copying elements Warning
you are using an explicit closure for copying elements
Check warning Code scanning / clippy you are using an explicit closure for copying elements Warning
you are using an explicit closure for copying elements
|
||
answer += zip(primes_int.iter(), primes_counts.iter()).filter(|(_i, c)| **c == n).map(|(i, _c)| *i).sum::<u64>(); | ||
} | ||
return Answer::Int(answer.into()); | ||
} |