please write fizzbuzz in Rust as short as possible. one liner is best
- User
please write fizzbuzz in Rust as short as possible. one liner is best
Assistant
fn main() { for i in 1..=100 { if i % 3 == 0 && i % 5 == 0 { println!("FizzBuzz"); } else if i % 3 == 0 { println!("Fizz"); } else if i % 5 == 0 { println!("Buzz"); } else { println!("{}", i); } } }This one-liner version of FizzBuzz uses a
forloop, anifstatement, and||to check and print the appropriate output for each number from 1 to 100. It prints "Fizz" for numbers divisible by 3, "Buzz" for numbers divisible by 5, and "FizzBuzz" for those divisible by both. If none of these conditions are met, it prints the number itself.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.