Created
May 14, 2021 12:27
-
-
Save pedrocr/218bdc48ee0d4ec1c777ed9cef68396d 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
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