-
-
Save rust-play/45794b6c4827916ddc8e5dda29aa9627 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(num: i64, list: &mut Vec<i64>) { | |
let exists: bool = list.contains(&num); | |
match exists { | |
true => {} | |
false => { | |
list.push(num); | |
let even: bool = num % 2 == 0; | |
match even { | |
true => collatz(num / 2, list), | |
false => collatz(3 * num + 1, list), | |
} | |
} | |
} | |
} | |
fn main() { | |
for x in -42..=42 { | |
let mut list: Vec<i64> = Vec::new(); | |
collatz(x, &mut list); | |
println!("collatz of {}: {:?}", x, &mut list) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment