Advertisement
Astra3

Untitled

Jun 20th, 2024
1,006
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.49 KB | None | 0 0
  1. fn main() {
  2.     for seed in 1u32..200_000_000u32 {
  3.         let coll = collatz(seed);
  4.         if seed % 1_000_000 == 0 {
  5.             println!("Seed: {} Steps: {}", seed, coll);
  6.         }
  7.     }
  8. }
  9.  
  10. fn collatz(mut seed: u32) -> u32 {
  11.     let mut steps = 0;
  12.     while seed > 1 {
  13.         while seed % 2 == 0 {
  14.             steps += 1;
  15.             seed /= 2;
  16.         }
  17.         if seed > 1 {
  18.             steps += 1;
  19.             seed = seed * 3 + 1;
  20.         }
  21.     }
  22.     return steps;
  23. }
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement