Scripting Helpers is winding down operations and is now read-only. More info→
← Blog Home

Snack Break Problem #1

About

Snack Break is a series of problems that I will be compiling and posting every Sunday! Each problem can be solved in 15 minutes or less, so I strongly encourage you to try to solve each one.

I think solving problems you have not encountered before is the best way to help train your ability to solve problems, an essential skill for any programmer. Hopefully you will find these problems useful!

You can find a copy of the first Snack Break problem here on github by selecting the 2015 folder and then selecting 1_May17_Fizzbuzz.lua.

The github repository will serve as an archive of every problem posted so far, so if you missed a week or look at a past problem you can always visit it.

This week's problem

Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz” instead. If the number is not divisible by either number, print out the number.

A solution and a new problem will be posted next week!

Commentary

Leave a Comment

DevChris says: May 17, 2015
@Arch Remember, the best solution to a problem is usually the easiest one. (purtal 2) So Vlatkovski's is more efficient here ;P
Archonious2 says: May 17, 2015
@Dev I already posted an efficient answer, then dogwarrior24 posted an obfuscated version, so I decided to make a more obfuscated one. However both our previous answers got removed before I posted the new obfuscated one, so only that remains.
Perci1 says: May 19, 2015
Too easy :/
Unclear says: May 21, 2015
Please avoid commenting solutions until a solution is released the Sunday after the problem is officially posted! Thanks! :)
DigitalVeer says: September 26, 2015
i=0;loadstring(("n=(i%3==0 and'Fizz'or'')..(i%5==0 and'Buzz'or'')print(n~=''and n or i)i=i+1;"):rep(100))()
Earthkingiv says: March 15, 2018
for i=1,100,1 do if i/5==math.floor(i/5) and i/3==mathfloor(i/3) then print("fizzbuzz") elseif i/3==math.floor(i/3) then print("fizz") elseif i/5==math.floor(i/5) then print("buzz") else print(i) end end
Yuuwa0519 says: June 16, 2019
for i = 1,100,1 do if i%3 == 0 and i%5 == 0 then print("FizzBuzz") elseif i%3 == 0 then print("Fizz") elseif i%5 == 0 then print("Buzz") else print(i) end end