Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Code shared from the Rust Playground
fn main() {
let mut buffer = String::new();
for i in 1..100 {
buffer = fizzbuzz(i, buffer);
println!("{}", buffer);
buffer.clear();
}
}
fn fizzbuzz(i: u32, mut buffer: String) -> String {
if i % 3 == 0 && i % 5 == 0 {
buffer.push_str("FizzBuzz")
} else if i % 3 == 0 {
buffer.push_str("Fizz")
} else if i % 5== 0 {
buffer.push_str("Buzz")
} else {
buffer.push_str(&format!("{}", i))
}
buffer
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.