Created
May 25, 2022 02:48
-
-
Save alexyvassili/8c6415a0d84ad979fba79a6b314e0535 to your computer and use it in GitHub Desktop.
Fizzbuzz.rs
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
use std::vec::Vec; | |
fn main() { | |
const COUNT: usize = 100; | |
let mut result = Vec::with_capacity(COUNT); | |
for i in 1..=COUNT { | |
let s = match (i % 3, i % 5) { | |
(0, 0) => String::from("FizzBuzz"), | |
(0, _) => String::from("Fizz"), | |
(_, 0) => String::from("Buzz"), | |
(_, _) => format!("{}", i), | |
}; | |
result.push(s); | |
} | |
print_result(&result); | |
} | |
fn print_result(result: &Vec<String>) { | |
for r in result { | |
println!("{}", r) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment