Created
March 26, 2018 17:08
-
-
Save rust-play/ccbc703cc4a81e148ed8c8174c47c551 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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
fn collatz(mut n: u64) -> Option<u64> { | |
let mut step = 0; | |
if n == 0 { | |
return None; | |
} | |
while n != 1 { | |
if n % 2 == 0 { | |
n /= 2; | |
} else { | |
n = 3 * n + 1; | |
} | |
step += 1; | |
} | |
Some(step) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment