Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created March 26, 2018 17:08
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 rust-play/ccbc703cc4a81e148ed8c8174c47c551 to your computer and use it in GitHub Desktop.
Save rust-play/ccbc703cc4a81e148ed8c8174c47c551 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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