From d1c85455e66fd514584d2d0bd0dbd9ebecefcf2e Mon Sep 17 00:00:00 2001 From: William Ball Date: Mon, 27 Jul 2020 12:17:05 -0700 Subject: [PATCH] optimizations --- rust/fourthfree/Cargo.toml | 2 +- rust/fourthfree/src/main.rs | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/rust/fourthfree/Cargo.toml b/rust/fourthfree/Cargo.toml index ed6ff3b..791dc62 100644 --- a/rust/fourthfree/Cargo.toml +++ b/rust/fourthfree/Cargo.toml @@ -7,4 +7,4 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -rug = "1.10.0" +rayon = "1.1" diff --git a/rust/fourthfree/src/main.rs b/rust/fourthfree/src/main.rs index c7d0104..e30a2d0 100644 --- a/rust/fourthfree/src/main.rs +++ b/rust/fourthfree/src/main.rs @@ -1,7 +1,9 @@ +use rayon::prelude::*; + // use std::thread; // const NUM_THREADS: usize = 12; -const BASE: u64 = 2; +const BASE: u64 = 10; fn is_fourth_free(x: &u64) -> bool { let mut i = 2; @@ -25,7 +27,7 @@ fn step(x: &u64) -> Vec { } fn next(ls: Vec) -> Vec { - ls.iter().map(step).flatten().collect() + ls.par_iter().map(step).flatten().collect() } // fn next(ls: Vec) -> Vec { @@ -62,7 +64,7 @@ fn main() { loop { i += 1; val += ls.len() as f64 / 2u64.pow(i) as f64; - ls = next(ls); println!("{}\t{}\t{}", i, ls.len(), val); + ls = next(ls); } }