Skip to content

Instantly share code, notes, and snippets.

@pedrocr
Created May 14, 2021 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pedrocr/218bdc48ee0d4ec1c777ed9cef68396d to your computer and use it in GitHub Desktop.
Save pedrocr/218bdc48ee0d4ec1c777ed9cef68396d to your computer and use it in GitHub Desktop.
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