Skip to content

Instantly share code, notes, and snippets.

@pedrocr
Created May 14, 2021
Embed
What would you like to do?
extern crate rayon;
use rayon::prelude::*;
use std::sync::atomic::{AtomicU8, Ordering};
fn main() {
let pos = AtomicU8::new(0);
(2..(u32::MAX as u64)).into_par_iter().for_each(|num| {
let mut inter = num;
while inter >= num {
if inter % 2 == 0 {
inter = inter / 2;
} else {
inter = (3 * inter + 1) / 2;
}
}
if num % (u32::MAX as u64 / 100) == 0 {
let val = pos.fetch_add(1, Ordering::SeqCst);
println!("Checked up to {}%", val+1);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment