Is the penalty to take a sip of your drink for an incorrect Fizz/Buzz/FizzBuzz result?
This brings back memories.
Here’s the straightforward approach,
eval(i) = if i % 3 == 0 && i % 5 == 0 then "FizzBuzz" else
if i % 3 == 0 then "Fizz" else
if i % 5 == 0 then "Buzz"
else toString(i);
foreach i in fromTo(0, 100)
select {i: eval(i)}
Here’s a slightly more clever approach,
div3(i) = if i % 3 == 0 then "Fizz" else "";
div5(i) = if i % 5 == 0 then "Buzz" else "";
or(str,i) = if length(str) == 0 then toString(i) else str;
foreach i in fromTo(0, 100)
select {i: or(div3(i) + div5(i), i) }
This was fun, thanks!
I think we need to exclude 0 in the result. Being pedantic….
foreach i in fromTo(1, 100)
let response = if i % 3 == 0 && i % 5 == 0
then "FizzBuzz"
else if i % 3 == 0
then "Fizz"
else if i % 5 == 0 then "Buzz" else toString(i)
select { i: response }
I do like the clever approach above though !
A silly solution as well….
timeX(x) =
foreach i in fromTo(1, 100)
where i % x == 0
select toString(i);
foreach x in n0]
let FizzBuzz = timeX(3 * 5)
let Fizz = timeX(3) - FizzBuzz
let Buzz = timeX(5) - FizzBuzz
let Numbers = timeX(1)
let Numeric = Numbers - Fizz - Buzz - FizzBuzz
foreach i in Numbers
let x = if i in Numeric
then i
else if i in Fizz
then "Fizz"
else if i in Buzz then "Buzz" else "FizzBuzz"
select { x }