Skip to main content

Who wants to play a game? Fizz buzz Challenge

  • June 7, 2024
  • 4 replies
  • 110 views
  • Translate

Forum|alt.badge.img+1

I like to give my team little challenges to exercise their NQE skills. Why don’t you play along this weekend and let’s see all the different ways you can accomplish this goal.

 

Tune in to see some creative ways to solve the FizzBuzz challenge with NQE

FizzBuzz


The task is to write a program that prints the numbers from 1 to 100, but with a twist:

  • For multiples of three, print "Fizz" instead of the number.
  • For multiples of five, print "Buzz" instead of the number.
  • For numbers which are multiples of both three and five, print "FizzBuzz" instead of the number.

4 replies

cariddir
Spotter
Forum|alt.badge.img+4
  • Spotter
  • 24 replies
  • June 7, 2024

Is the penalty to take a sip of your drink for  an incorrect Fizz/Buzz/FizzBuzz result?
This brings back memories.

Translate

  • Employee
  • 4 replies
  • June 7, 2024

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! 😄

Translate

Forum|alt.badge.img+4
  • Spotter
  • 18 replies
  • June 7, 2024

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 !

Translate

Forum|alt.badge.img+4
  • Spotter
  • 18 replies
  • June 7, 2024

A silly solution as well….

timeX(x) =
  foreach i in fromTo(1, 100)
  where i % x == 0
  select toString(i);

foreach x in [0]
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 }

 

Translate

Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings