Created
May 20, 2016 00:50
-
-
Save lotabout/0236e5d994be3f34a20cc7dc26c8219a to your computer and use it in GitHub Desktop.
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
fn gen_wheel(primes: Vec<u64>) -> Box<std::iter::Iterator<Item = u64>> { | |
let mul = primes.iter().fold(1, |acc, x| acc * x); | |
let stroke_left: Vec<_>= (2..(mul+1)) | |
.filter(|x| primes.iter().all(|&y| x % y != 0)) | |
.collect(); | |
let front_wheel: Vec<_> = vec![0].iter().chain(primes.iter()) | |
.zip(primes.iter().chain(stroke_left.iter().take(1))) | |
.map(|(&x, &y)| y - x) | |
.collect(); | |
let diff_wheel: Vec<_>= vec![1].iter().chain(stroke_left.iter()) | |
.zip(stroke_left.iter().chain(vec![mul+1].iter())) | |
.map(|(&x, &y)| y - x) | |
.collect(); | |
Box::new(front_wheel.into_iter().chain(diff_wheel.into_iter().cycle().skip(1))) | |
} | |
pub fn main() { | |
let wheel = gen_wheel(vec![2,3]); | |
for i in wheel.take(30) { | |
println!("i = {}", i); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment