finish 37
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "euler37"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
primes = {version = "*", path = "../../lib/primes"}
|
||||
@@ -0,0 +1,32 @@
|
||||
extern crate primes;
|
||||
|
||||
use primes::Primes;
|
||||
|
||||
fn main() {
|
||||
let primes = Primes::get_between(2, 1_000_000);
|
||||
let mut result = vec![];
|
||||
for p in &primes.vector {
|
||||
if is_truncatable(*p, &primes) {
|
||||
result.push(*p);
|
||||
if result.len() == 11 {
|
||||
println!("{}", result.iter().sum::<u32>());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn is_truncatable(x: u32, primes: &Primes<u32>) -> bool {
|
||||
if x < 10 {
|
||||
return false;
|
||||
}
|
||||
let s = x.to_string();
|
||||
for i in 1..s.len() {
|
||||
if !primes.contains(&s[i..].parse().unwrap()) {
|
||||
return false;
|
||||
}
|
||||
if !primes.contains(&s[..i].parse().unwrap()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
Reference in New Issue
Block a user