4 ms·
fn main() { for i in 1..101 { if i % 15 == 0 { println!("FizzBuzz"); } else if i % 3 == 0 { println!("Fizz");
by lisivka 10y ago
fn main() {
for i in 1..101 {
if i % 15 == 0 {
println!("FizzBuzz");
} else if i % 3 == 0 {
println!("Fizz");
} else if i % 5 == 0 {
println!("Buzz");
} else {
println!("{}", i);
}
}
}
- flukus 10y agoI don't know why people over complicate things. I was searching for other solutions and found this abomination: https://bitbucket.org/iopq/fizzbuzz-in-rust/src/bf4968973d73137f0dfd07205d599bed30a788fa/src/lib.rs?at=master&fileviewer=file-view-default https://bitbucket.org/iopq/fizzbuzz-in-rust/src/bf4968973d73... I hope their production code isn't like this.
- iopq 10y agoI wrote this as an exercise. This is specifically written to be point-free code without any if or match expressions. .unwrap_or_else(|| i.to_string().into()) this is the only one that was too ugly to make point-free
- Ygg2 10y agoWut? It's about as representative of Rust as writing FizzBuzz using Monads. In Java. If you want production code look at Rust and Servo.