Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn main() {
- for seed in 1u32..200_000_000u32 {
- let coll = collatz(seed);
- if seed % 1_000_000 == 0 {
- println!("Seed: {} Steps: {}", seed, coll);
- }
- }
- }
- fn collatz(mut seed: u32) -> u32 {
- let mut steps = 0;
- while seed > 1 {
- while seed % 2 == 0 {
- steps += 1;
- seed /= 2;
- }
- if seed > 1 {
- steps += 1;
- seed = seed * 3 + 1;
- }
- }
- return steps;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement