Hello! I have a fun challenge, and I want to see if it is possible to improve my solution. Instead of making a clean an idiomatic program, I want to try to solve the Fizz buzz problem as confusingly as possible. (Why? Because I thought it would be funny.) My current best implementation uses the short-circuiting nature of &&
, but I'm wondering if it is possible to push the challenge any further.
const MAX: usize = 20;
fn basic() {
for i in 1..=MAX {
if i % 15 == 0 {
println!("fizzbuzz");
} else if i % 3 == 0 {
println!("fizz");
} else if i % 5 == 0 {
println!("buzz");
} else {
println!("{}", i);
}
}
}
fn complex() {
for i in 1..=MAX {
if (i % 15 == 0 && println!("fizzbuzz") == ())
|| (i % 3 == 0 && println!("fizz") == ())
|| (i % 5 == 0 && println!("buzz") == ())
|| println!("{i}") == () {}
}
}
fn obfuscated() {
for i in 1..=MAX {
if !(i%15==0&&println!("fizzbuzz")==()||i%3==0&&println!("fizz")==()||i%5==0&&println!("buzz")==()) {
println!("{i}");
}
}
}
fn main() {
obfuscated();
}
Any attempts / suggestions are appreciated!