From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

BreakPoint

cancel
Showing results for 
Search instead for 
Did you mean: 

fizbuzz - a simple coding challenge

Did all this somehow turn into a Rube Goldberg competition? 😄

0 Kudos
Message 31 of 41
(8,826 Views)

For me: yes 🙂

Kind Regards,
Thierry C - CLA, CTA - Senior R&D Engineer (Former Support Engineer) - National Instruments
If someone helped you, let them know. Mark as solved and/or give a kudo. 😉
Message 32 of 41
(8,815 Views)

jcarmody wrote:

@Henrik Volkers wrote:

 

How about a one line regular expression someone? 


Hmmm...


I don't know if it's possible with one line, but I had to try this puzzle using regex,

 

Regex FizzBuzz.png

Certified-LabVIEW-Architect_rgb.jpgCertified_TestStand_Architect_rgb.jpg


"I won't be wronged. I won't be insulted. I won't be laid a-hand on. I don't do these things to other people, and I require the same from them." John Bernard Books

Message 33 of 41
(8,770 Views)

Here's two ideas for a Rube Goldberg version of fizzbuzz... 😄

 

1) A VI that, for every integer n, run queries on Wolfram Alpha to check whether n is divisible by 3 and 5. Use the true or false responses to build your list of fizzes and buzzes. Remember to put in a nice long delay in your loop to avoid being blacklisted for denial of service...

 

2) Add the digits of the integer n together, and check whether the sum is divisible by three. Check the last digit to see whether it's 0 or 5, and proceed. You could be lazy and use Q&R to check the divisibility of the sum, but why stop there? This is supposed to be a Rube, goddamnit!

 

Actually, thinking about it, using the second allows you to test huge numbers:

 

rubediv3a.png

---
CLA
0 Kudos
Message 34 of 41
(8,755 Views)

Fizzbuzz mentioned on Codeless Code, here - http://thecodelesscode.com/case/187

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 35 of 41
(8,026 Views)

Pardon the ressurection, but I just read this thread and had to claim the least number of functions. Would have been less if I didn't have to stop at 100.

FizzBuzz.png

Josh
Software is never really finished, it's just an acceptable level of broken
0 Kudos
Message 36 of 41
(7,773 Views)

Resurrecting the thread after exactly six years with a Python/regex solution:

 

 

import re

for i in range(1,101):
    out = ''
    if(re.search('^(0|1(01*0)*1)*$', bin(i)[2:])): out = 'FIZZ'
    if(re.search('[0-9]?[05]$', str(i))) : out += 'BUZZ'
    if(out == ''): out = str(i)
    print(out)

 

 

jcarmody_0-1625077944649.png

 

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 37 of 41
(4,483 Views)

@jcarmody wrote:

Resurrecting the thread after exactly six years with a Python/regex solution:

import re

for i in range(1,101):
    out = ''
    if(re.search('^(0|1(01*0)*1)*$', bin(i)[2:])): out = 'FIZZ'
    if(re.search('[0-9]?[05]$', str(i))) : out += 'BUZZ'
    if(out == ''): out = str(i)
    print(out)

 


That source is flawed 😋.

 

Requirements clearly state to output "Fizz", "Buzz" and "FizzBuzz". Not "FIZZ", "BUZZ" and "FIZZBUZZ":

 

Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".

 

0 Kudos
Message 38 of 41
(4,460 Views)

I do love my selects (a back to the basics code)

 

AeroSoul_0-1625464936464.png

 

0 Kudos
Message 39 of 41
(4,408 Views)

@AeroSoul wrote:

I do love my selects (a back to the basics code)

So basically this ancient thread went full circle, because that's what started it all. Except that you now do a lot of string manipulations that you throw away in most cases a nanosecond later. So why do them unless needed? Also note that there is an "empty string?" primitive.

 

Compare that to the simplicity of e.g. my version.

 

 

0 Kudos
Message 40 of 41
(4,398 Views)