diff --git a/hello_cargo/src/main.rs b/hello_cargo/src/main.rs index e7a11a9..8f80109 100644 --- a/hello_cargo/src/main.rs +++ b/hello_cargo/src/main.rs @@ -1,3 +1,30 @@ fn main() { println!("Hello, world!"); + fizzbuzz_to(100); } + +fn is_divisible_by(lhs: u32, rhs: u32) -> bool { + if rhs == 0 { + return false; + } + + lhs % rhs == 0 +} + +fn fizzbuzz(n: u32) -> () { + if is_divisible_by(n, 15) { + println!("fizzbuzz"); + } else if is_divisible_by(n, 3) { + println!("fizz"); + } else if is_divisible_by(n, 5) { + println!("buzz"); + } else { + println!("{}", n); + } +} + +fn fizzbuzz_to(n: u32) { + for n in 1..n + 1 { + fizzbuzz(n); + } +} \ No newline at end of file