-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Solve p111 in rust #43
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||
Check warning Code scanning / clippy variable does not need to be mutable Warning
variable does not need to be mutable
Check warning Code scanning / clippy variable does not need to be mutable Warning
variable does not need to be mutable
Check warning Code scanning / clippy unused variable: answer Warning
unused variable: answer
Check warning Code scanning / clippy unused variable: answer Warning
unused variable: answer
|
||
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(); | ||
|
||
answer += zip(primes_int.iter(), primes_counts.iter()).filter(|(_i, c)| **c == n).map(|(i, _c)| *i).sum::<u64>(); | ||
} | ||
return Answer::Int(answer.into()); | ||
} |
Check warning
Code scanning / clippy
unused import: std::iter::zip Warning