expanding search

This commit is contained in:
William Ball 2020-07-12 16:00:58 -07:00
parent 898dbb40d9
commit 4f8d69c769

View file

@ -16,14 +16,14 @@ impl Tree {
} }
} }
fn to_string(&self) -> String { // fn to_string(&self) -> String {
let mut retval = format!("[{}: ", self.value); // let mut retval = format!("[{}: ", self.value);
for child in &self.children { // for child in &self.children {
retval.push_str(&child.to_string()[..]); // retval.push_str(&child.to_string()[..]);
} // }
retval.push(']'); // retval.push(']');
retval // retval
} // }
fn step(&mut self) { fn step(&mut self) {
if self.children.is_empty() { if self.children.is_empty() {
@ -70,11 +70,17 @@ fn step(x: u64) -> Vec<u64> {
} }
fn main() { fn main() {
let primes: Vec<u64> = primal::Primes::all().skip_while(|x| *x < 10_000_000).take_while(|x| *x < 100_000_000).map(|x| x as u64).collect(); /* find all non-truncatable primes in (100,000,000; 1,000,000,000) */
let primes: Vec<u64> = primal::Primes::all()
.skip_while(|x| *x < 100_000_000)
.take_while(|x| *x < 1_000_000_000)
.map(|x| x as u64)
.filter(|x| !(primal::is_prime(*x / 10)))
.collect();
let mut tree = Tree::new(0, primes); let mut tree = Tree::new(0, primes);
for _ in 0..20 { for _ in 0..20 {
tree.step(); tree.step();
println!("{:?}", tree.longest_path()); println!("{:?}", tree.longest_path());
} }
//println!("{}", tree.to_string());
} }