Your task is to write a Rust program that implements the classic programming challenge known as FizzBuzz.
You are given a function fizz_buzz(num: u32) -> String
that takes a single parameter num
of type u32
and returns a String
.
Your job is to return a string based on the following rules:
Here's how the behavior of the function should look like:
Good luck, and happy coding!
kennethlove
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge if num % 5 == 0 && num % 3 == 0 { "FizzBuzz".to_string() } else if num % 5 == 0 { "Buzz".to_string() } else if num % 3 == 0 { "Fizz".to_string() } else { format!("{}", num) }}
tobiaszfilar
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge if num % 3 == 0 && num % 5 == 0 { return "FizzBuzz".to_string(); } else if num % 3 == 0 { return "Fizz".to_string() } else if num % 5 == 0 { return "Buzz".to_string() } num.to_string()}
kylenoteboom
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge if num % 3 == 0 && num % 5 == 0 { return "FizzBuzz".to_string(); } else { if num % 3 == 0 { return "Fizz".to_string(); } else if num % 5 == 0 { return "Buzz".to_string(); } } num.to_string()}
leenalmajz
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge if num % 3 == 0 && num % 5 == 0 { return String::from("FizzBuzz") } else if num % 3 == 0 { return String::from("Fizz") } else if num % 5 == 0 { return String::from("Buzz") } else { return num.to_string() }}
takes-ki
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge match (num % 3, num % 5) { (0, 0) => "FizzBuzz".to_string(), (0, _) => "Fizz".to_string(), (_, 0) => "Buzz".to_string(), (_, _) => num.to_string() }}
xenonminer
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge if num % 15 == 0 { "FizzBuzz".to_string() } else if num % 5 == 0 { "Buzz".to_string() } else if num % 3 == 0 { "Fizz".to_string() } else { num.to_string() }}
jimlawton
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge if num % 5 == 0 && num % 3 == 0 { String::from("FizzBuzz") } else if num % 5 == 0 { String::from("Buzz") } else if num % 3 == 0 { String::from("Fizz") } else { num.to_string() }}
5822791760
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge let mut result = String::new(); if num % 3 == 0 { result.push_str("Fizz"); } if num % 5 == 0 { result.push_str("Buzz"); } result}
XtebanUy
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge match (num % 3, num % 5) { (0, 0) => String::from("FizzBuzz"), (0, _) => String::from("Fizz"), (_, 0) => String::from("Buzz"), _ => format!("{num}") }}
XtebanUy
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge let mut result = String::new(); if num % 3 == 0 { result.push_str("Fizz"); } if num % 5 == 0 { result.push_str("Buzz"); } result}
mbergkvist
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge match (num % 3, num %5) { (0, 0) => String::from("FizzBuzz"), (0, _) => String::from("Fizz"), (_, 0) => String::from("Buzz"), _ => format!("{num}") }}
facat
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge match num { n if n % 3 == 0 && n % 5 == 0 => "FizzBuzz".to_string(), n if n % 3 == 0 => "Fizz".to_string(), n if n % 5 == 0 => "Buzz".to_string(), n => format!("{n}"), }}
DivineGod
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge match num { n if n % 3 == 0 && n % 5 == 0 => "FizzBuzz".to_string(), n if n % 3 == 0 => "Fizz".to_string(), n if n % 5 == 0 => "Buzz".to_string(), n => format!("{n}"), }}
mehdihmr
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge if num % 3 == 0 && num % 5 == 0{ return "FizzBuzz".to_string(); } else if num % 5 == 0{ return "Buzz".to_string(); } else if num % 3 == 0 { return "Fizz".to_string(); } else { return num.to_string(); }}
MisterWoody
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge match num { n if n % (5 * 3) == 0 => "FizzBuzz".to_string(), n if n % 3 == 0 => "Fizz".to_string(), n if n % 5 == 0 => "Buzz".to_string(), _ => num.to_string(), }}
ethel-dev
pub fn fizz_buzz(num: u32) -> String { if num % 3 == 0 && num % 5 == 0 { return "FizzBuzz".to_string() } if num % 3 == 0 { return "Fizz".to_string() } if num % 5 == 0 { return "Buzz".to_string() } num.to_string()}
Algorab
pub fn fizz_buzz(num: u32) -> String { let mut fizzbuzz = String::new(); if num % 3 == 0 { fizzbuzz.push_str("Fizz"); } if num % 5 == 0 { fizzbuzz.push_str("Buzz"); } if fizzbuzz.is_empty() { fizzbuzz.push_str(num.to_string().as_str()); } fizzbuzz}
sroas
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge let multiple_of_three = num % 3 == 0; let multiple_of_five = num % 5 == 0; if multiple_of_three && multiple_of_five { "FizzBuzz".to_string() } else if multiple_of_three { "Fizz".to_string() } else if multiple_of_five { "Buzz".to_string() } else { num.to_string() }}
felipebalbi
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge let mut output = String::new(); if num % 5 == 0 || num % 3 == 0 { if num % 3 == 0 { output.push_str("Fizz"); } if num % 5 == 0 { output.push_str("Buzz"); } } else { output.push_str(&num.to_string()); } output}
xiuchiliudu
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge if num % 15 == 0 { "FizzBuzz".to_string() } else if num % 3 == 0 { "Fizz".to_string() } else if num % 5 == 0 { "Buzz".to_string() } else { format!("{}", num) }}
danielmpetrov
pub fn fizz_buzz(num: u32) -> String { match num { x if x % 15 == 0 => "FizzBuzz".to_string(), x if x % 3 == 0 => "Fizz".to_string(), x if x % 5 == 0 => "Buzz".to_string(), x => x.to_string(), }}
yoakemae
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge if num % 3 == 0 && num % 5 == 0 { return "FizzBuzz".to_string(); } else if num % 3 == 0 { return "Fizz".to_string(); } else if num % 5 == 0 { return "Buzz".to_string(); } else { return num.to_string(); }}
tinthid
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge if num % 15 == 0 { return String::from("FizzBuzz"); } if num % 5 == 0 { return String::from("Buzz"); } if num % 3 == 0 { return String::from("Fizz"); } num.to_string()}
qiyuan711
pub fn fizz_buzz(num: u32) -> String { match (num % 3 == 0, num % 5 == 0) { (true, true) => "FizzBuzz".to_string(), (true, false) => "Fizz".to_string(), (false, true) => "Buzz".to_string(), _ => num.to_string(), }}
jw
pub fn fizz_buzz(num: u32) -> String { match num { n if n % 3 == 0 && n % 5 == 0 => "FizzBuzz".to_string(), n if n % 3 == 0 => "Fizz".to_string(), n if n % 5 == 0 => "Buzz".to_string(), _ => num.to_string(), }}
nickythorne
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge match num { n if n % 3 == 0 && n % 5 == 0 => return "FizzBuzz".to_string(), n if n % 3 == 0 => return "Fizz".to_string(), n if n % 5 == 0 => return "Buzz".to_string(), _ => return num.to_string() };}
DV-13
pub fn fizz_buzz(num: u32) -> String { match (num % 3 == 0, num % 5 == 0) { (true, true) => "FizzBuzz".to_string(), (true, false) => "Fizz".to_string(), (false, true) => "Buzz".to_string(), _ => num.to_string(), }}
RonaldoArayadev
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge let mut b:bool = false; let mut ret:String = String::from(""); if num % 3 == 0 { ret.push_str("Fizz"); b = true; } if num % 5 == 0 { ret.push_str("Buzz"); b = true; } if b == false { ret.push_str(&num.to_string()); } ret }
martin-unit
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge if num % 15 == 0 { "FizzBuzz".to_string() } else if num % 5 == 0 { "Buzz".to_string() } else if num % 3 == 0 { "Fizz".to_string() } else { num.to_string() }}
martin-unit
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge if num % 15 == 0 { "FizzBuzz".to_string() } else if num % 5 == 0 { "Buzz".to_string() } else if num % 3 == 0 { "Fizz".to_string() } else { num.to_string() }}
vrzwflng
pub fn fizz_buzz(num: u32) -> String { if num % (3 * 5) == 0 { String::from("FizzBuzz") } else if num % 3 == 0 { String::from("Fizz") } else if num % 5 == 0 { String::from("Buzz") } else { num.to_string() }}
joeslow
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge if num % 3 == 0 && num % 5 == 0 { "FizzBuzz".to_string() } else if num % 3 == 0 { "Fizz".to_string() } else if num % 5 == 0 { "Buzz".to_string() } else { num.to_string() }}
Thymelizabeth
pub fn fizz_buzz(num: u32) -> String { let mut result = String::new(); if num % 3 == 0 { result += "Fizz"; } if num % 5 == 0 { result += "Buzz"; } if result.is_empty() { format!("{}", num) } else { result }}
konishu
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge if num % 3 == 0 && num % 5 == 0 { "FizzBuzz".to_string() } else if num % 5 == 0 { "Buzz".to_string() } else if num % 3 == 0 { "Fizz".to_string() } else { num.to_string() }}
tamanishi
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge if num % 15 == 0 { "FizzBuzz".to_string() } else if num % 3 == 0 { "Fizz".to_string() } else if num % 5 == 0 { "Buzz".to_string() } else { num.to_string() }}
devarajang
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge let output:String; if num % 15 == 0 { output = String::from("FizzBuzz"); } else if num % 5 == 0 { output = String::from("Buzz"); } else if num % 3 == 0{ output = String::from("Fizz"); } else { output = String::from(format!("{}", num)); } return output;}
nichideropa
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge if num % (3 * 5) as u32 == 0 { String::from("FizzBuzz") } else if num % 3 == 0 { String::from("Fizz") } else if num % 5 == 0 { String::from("Buzz") } else { num.to_string() }}
nichideropa
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge if num % (3 * 5) as u32 == 0 { String::from("FizzBuzz") } else if num % 3 == 0 { String::from("Fizz") } else if num % 5 == 0 { String::from("Buzz") } else { num.to_string() }}
jeypiti
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge if num % 15 == 0 { String::from("FizzBuzz") } else if num % 3 == 0 { String::from("Fizz") } else if num % 5 == 0 { String::from("Buzz") } else { num.to_string() }}
stefafafan
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge if num % 3 == 0 && num % 5 == 0 { "FizzBuzz".to_string() } else if num % 3 == 0 { "Fizz".to_string() } else if num % 5 == 0 { "Buzz".to_string() } else { num.to_string() }}
0xsmarter
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge match num { x if x % 3 == 0 && x % 5 == 0 => "FizzBuzz".to_string(), x if x % 3 == 0 => "Fizz".to_string(), x if x % 5 == 0 => "Buzz".to_string(), _ => num.to_string() }}
t3stlab
pub fn fizz_buzz(num: u32) -> String { match num { x if x % 3 == 0 && x % 5 == 0 => "FizzBuzz".to_string(), x if x % 3 == 0 => "Fizz".to_string(), x if x % 5 == 0 => "Buzz".to_string(), _ => num.to_string() }}
aidan1magee
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge if num % 3 == 0 && num % 5 == 0{ "FizzBuzz".to_string() } else if num % 3 == 0 { "Fizz".to_string() } else if num % 5 == 0{ "Buzz".to_string() } else { num.to_string() }}
tsucchinoko
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge match num { x if x % 3 == 0 && x % 5 == 0 => "FizzBuzz".to_string(), x if x % 3 == 0 => "Fizz".to_string(), x if x % 5 == 0 => "Buzz".to_string(), _ => num.to_string() }}
ankeetparikh
pub fn fizz_buzz(num: u32) -> String { if num % 15 == 0 { "FizzBuzz".to_string() } else if num % 3 == 0 { "Fizz".to_string() } else if num % 5 == 0 { "Buzz".to_string() } else { num.to_string() }}
maxvi
pub fn fizz_buzz(num: u32) -> String { match num { x if x % 3 == 0 && x % 5 == 0 => "FizzBuzz".to_string(), x if x % 3 == 0 => "Fizz".to_string(), x if x % 5 == 0 => "Buzz".to_string(), _ => num.to_string(), }}
gjmvervoort
pub fn fizz_buzz(num: u32) -> String { if num % 3 == 0 && num % 5 == 0 { "FizzBuzz".to_string() } else if num % 3 == 0 { "Fizz".to_string() } else if num % 5 == 0 { "Buzz".to_string() } else { num.to_string() }}
LauriSarap
pub fn fizz_buzz(num: u32) -> String { match num { _ if num % 3 == 0 && num % 5 == 0 => return "FizzBuzz".to_string(), _ if num % 3 == 0 => return "Fizz".to_string(), _ if num % 5 == 0 => return "Buzz".to_string(), _ => return num.to_string(), }}
Kobeieii
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge let mod_3 = num % 3; let mod_5 = num % 5; if mod_3 == 0 && mod_5 == 0 { "FizzBuzz".to_string() } else if mod_3 == 0 { "Fizz".to_string() } else if mod_5 == 0 { "Buzz".to_string() } else { num.to_string() }}
StimhackSoftware
use std::ops::Rem;pub fn fizz_buzz(num: u32) -> String { if num.rem(15) == 0 { "FizzBuzz".to_string() } else if num.rem(5) == 0 { "Buzz".to_string() } else if num.rem(3) == 0 { "Fizz".to_string() } else { num.to_string() }}