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!
ogaca42
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() }}
Maki-SIO
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() }}
Mxn-ptr
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() }}
ShileiShen
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge let fizz_flag = num % 3 == 0; let buzz_flag = num % 5 == 0; if fizz_flag && buzz_flag { String::from("FizzBuzz") } else if fizz_flag { String::from("Fizz") } else if buzz_flag { String::from("Buzz") } else { String::from(num.to_string()) }}
jamtg
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 { format!("{num}") }}
yansq
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge let (d3, d5) = (num % 3 == 0, num % 5 == 0); match (d3, d5) { (true, false) => String::from("Fizz"), (false, true) => String::from("Buzz"), (true, true) => String::from("FizzBuzz"), _ => num.to_string() }}
yansq
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge let (mut d3, mut d5) = (num % 3 == 0, num % 5 == 0); match (d3, d5) { (true, false) => String::from("Fizz"), (false, true) => String::from("Buzz"), (true, true) => String::from("FizzBuzz"), _ => num.to_string() }}
macgeargear
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 { "Fizz".to_string() }}
funny233-github
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge if num % 3 == 0 && num % 5 != 0 { return "Fizz".into() } if num % 3 == 0 && num % 5 == 0 { return "FizzBuzz".into() } if num % 3 != 0 && num % 5 == 0 { return "Buzz".into() } num.to_string() }
zelsazgh
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge if num % 3 == 0 && num % 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() }}
jose-bernardo
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge let mut s: String; match num { n if n % 15 == 0 => s = "FizzBuzz".to_string(), n if n % 3 == 0 => s = "Fizz".to_string(), n if n % 5 == 0 => s = "Buzz".to_string(), _ => s = num.to_string(), } return s;}
tiagombsilva
pub fn fizz_buzz(num: u32) -> String { let string: String; if num % 3 == 0 && num % 5 == 0{ string = String::from("FizzBuzz"); }else if num % 3 == 0 { string = String::from("Fizz"); }else if num % 5 == 0 { string = String::from("Buzz"); }else{ string = num.to_string() } string}
digitalresistor
pub fn fizz_buzz(num: u32) -> String { match num { n if (n % 15 == 0) => return "FizzBuzz".to_string(), n if (n % 3 == 0) => return "Fizz".to_string(), n if (n % 5 == 0) => return "Buzz".to_string(), n => return format!("{n}") }}
digitalresistor
pub fn fizz_buzz(num: u32) -> String { 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(), n => return format!("{n}") }}
carlos-quantexai
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 { num.to_string() }}
radloffl
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge let isMultipleOf3 = (num % 3) == 0; let isMultipleOf5 = (num % 5) == 0; if isMultipleOf3 && isMultipleOf5 { return "FizzBuzz".to_string(); } else if isMultipleOf3 { return "Fizz".to_string(); } else if isMultipleOf5 { return "Buzz".to_string(); } else { return num.to_string(); }}
retinotopic
pub fn fizz_buzz(num: u32) -> String { let mut mystr: String = String::from(""); if num % 3 == 0 { mystr.push_str("Fizz"); } if num % 5 == 0 { mystr.push_str("Buzz"); } return mystr;}
majesticalcreature
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge let assign = [(15, "FizzBuzz"), (5, "Buzz"), (3, "Fizz")]; for (div, msg) in assign { if num % div == 0 { return String::from(msg); } } String::from("{num}")}
jhq223
pub fn fizz_buzz(num: u32) -> String { match (num % 3, num % 5) { (0, 0) => "FizzBuzz".to_string(), (0, _) => "Fizz".to_string(), (_, 0) => "Buzz".to_string(), (_, _) => { num.to_string() } }}
xbarnett
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"), _ => num.to_string(), }}
mk-comm
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() }}
Johnchoi913
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge 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(), }}
majesticalcreature
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge let div = vec![15, 5, 3]; let strs = vec!["FizzBuzz", "Buzz", "Fizz"]; for (i, d) in div.iter().enumerate() { if num % d == 0 { return String::from(strs[i]); } } String::from("{num}")}
matei
pub fn fizz_buzz(num: u32) -> String { if num % 15 == 0 { String::from("FizzBuzz") } else if num % 5 == 0 { "Buzz".to_string() } else if num % 3 == 0 { "Fizz".to_string() } else { num.to_string() } }
sander-b-postnl
pub fn fizz_buzz(num: u32) -> String { match num { n if n % 15 == 0 => "FizzBuzz".to_string(), n if n % 3 == 0 => "Fizz".to_string(), n if n % 5 == 0 => "Buzz".to_string(), n => n.to_string(), }}
edoardo-morosanu
pub fn fizz_buzz(num: u32) -> String { if num % 3 == 0 { if num % 5 == 0 { return String::from("FizzBuzz") } return String::from("Fizz") } else if num % 5 == 0 { return String::from("Buzz") } else { return num.to_string(); }}
edoardo-morosanu
pub fn fizz_buzz(num: u32) -> String { if num % 3 == 0 { if num % 5 == 0 { return String::from("FizzBuzz") } return String::from("Fizz") } else if num % 5 == 0 { return String::from("Buzz") } else { return num.to_string(); }}
i5-650
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 { format!("{}", num) }}
amassare
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge let mut res=String::new(); if num%3==0{ res.push_str("Fizz"); } if num%5==0{ res.push_str("Buzz"); } res}
alexromanov
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge let mut result = ""; if num % 3 == 0 && num % 5 == 0{ return String::from("FizzBuzz"); } else if num % 5 == 0 { return String::from("Buzz"); } else if num % 3 == 0 { return String::from("Fizz"); } else { return num.to_string(); }}
zavakid
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge if num % 15 == 0 { "FizzBuzz".into() } else if num % 3 == 0 { "Fizz".into() } else if num % 5 == 0 { "Buzz".into() } else { num.to_string() }}
RiskyRomero
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge match (num % 3 == 0, num % 5 == 0) { (true, false) => "Fizz".to_string(), (false, true) => "Buzz".to_string(), (true, true) => "FizzBuzz".to_string(), _ => num.to_string() }}
IdoPort
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge match (num % 3 == 0, num % 5 == 0) { (true, false) => "Fizz".to_string(), (false, true) => "Buzz".to_string(), (true, true) => "FizzBuzz".to_string(), (false, false) => num.to_string() }}
Ustin
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge if num % 3 != 0 && num % 5 != 0 { return format!("{num}"); } let mut res = "".to_string(); if num % 3 == 0 { res += "Fizz"; }; if num % 5 == 0 { res += "Buzz"; }; return res;}
LaurentiuStoleriu
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge let Fizz = "Fizz".to_string(); let Buzz = "Buzz".to_string(); let mut FizzBuzz = String::new(); if num % 3 == 0 { FizzBuzz.push_str(&Fizz); } if num % 5 == 0 { FizzBuzz.push_str(&Buzz); } if (num % 3 != 0) && (num % 5 != 0) { FizzBuzz.push_str(&num.to_string()); } FizzBuzz}
dylan-park
pub fn fizz_buzz(num: u32) -> String { match (num % 3 == 0, num % 5 == 0) { (true, false) => "Fizz".to_string(), (false, true) => "Buzz".to_string(), (true, true) => "FizzBuzz".to_string(), (false, false) => num.to_string(), }}
shankun
pub fn fizz_buzz(num: u32) -> String { if num % 3 == 0 { if num % 5 == 0 { String::from("FizzBuzz") } else { String::from("Fizz") } } else if num % 5 == 0 { String::from("Buzz") } else { num.to_string() }}
Parallaxes
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge match num { num if num % 15 == 0 => String::from("FizzBuzz"), num if num % 5 == 0 => String::from("Buzz"), num if num % 3 == 0 => String::from("Fizz"), _ => num.to_string(), }}
Xinoi
pub fn fizz_buzz(num: u32) -> String { match (num%3 == 0, num%5 == 0) { (true, false) => "Fizz".to_string(), (false, true) => "Buzz".to_string(), (true, true) => "FizzBuzz".to_string(), _ => num.to_string(), }}
otherJL0
pub fn fizz_buzz(num: u32) -> String { match num { num if num % 15 == 0 => String::from("FizzBuzz"), num if num % 5 == 0 => String::from("Buzz"), num if num % 3 == 0 => String::from("Fizz"), _ => num.to_string(), }}
CianciuStyles
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge match (num % 3 == 0, num % 5 == 0) { (true, true) => "FizzBuzz".to_string(), (true, false) => "Fizz".to_string(), (false, true) => "Buzz".to_string(), (false, false) => num.to_string() }}
ayushrawat10
pub fn fizz_buzz(num: u32) -> String { match num { fb if (fb%3 == 0 && fb%5 == 0) => { return "FizzBuzz".to_owned(); }, f if (f%3 == 0) => { return String::from("Fizz"); }, b if (b%5 == 0) => { return String::from("Buzz"); } r => r.to_string(), } }
ayushrawat10
pub fn fizz_buzz(num: u32) -> String { match num%3 { 0 => { if num%5 == 0 { return "FizzBuzz".to_owned(); } return "Fizz".to_owned(); }, _ => { }, } match num%5 { 0 => "Buzz".to_owned(), r => r.to_string(), }}
pbjarterot
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 %5 == 0 { return String::from("Buzz"); } else if num % 3 == 0 { return String::from("Fizz"); } else { return num.to_string(); }}
masteryachty
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() } (false, false) => { num.to_string() } }}
damascussteel21
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge if num % 3 == 0 && num % 5 == 0 { String::from("FizzBuzz") } else if num % 3 == 0 { String::from("Fizz") } else if num % 5 == 0 { String::from("Buzz") } else { format!("{}", num) }}
kyhou
pub fn fizz_buzz(num: u32) -> String { match num { x if x % 3 == 0 && x % 5 != 0 => "Fizz".to_string(), x if x % 5 == 0 && x % 3 != 0 => "Buzz".to_string(), x if x % 3 == 0 && x % 3 == 0 => "FizzBuzz".to_string(), _ => num.to_string() }}
oneopane
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge match (num % 3 == 0, num % 5 == 0) { (true, true) => String::from("FizzBuzz"), (true, false) => String::from("Fizz"), (false, true) => String::from("Buzz"), (false, false) => num.to_string() }}
AtJiawei
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge let remainder_3 = num % 3; let remainder_5 = num % 5; if remainder_3 ==0 && remainder_5== 0 { "FizzBuzz".to_string() } else if remainder_3 == 0{ "Fizz".to_string() } else if remainder_5 == 0 { "Buzz".to_string() } else { num.to_string() }}
Aditeya
pub fn fizz_buzz(num: u32) -> String { // TODO: Implement the FizzBuzz challenge let three = num % 3 == 0; let five = num % 5 == 0; if !(three || five) { return num.to_string(); } let mut s = String::with_capacity(8); if three { s.push_str("Fizz"); } if five { s.push_str("Buzz"); } s}