Created
May 27, 2019 11:42
Star
You must be signed in to star a gist
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 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