2 ms·
I tend to memorize it like this: If number modulus 3 is true, print "Fizz" If number modulus 5 is true, print "Buzz" If number modulus 15 is true, print
by stefanos82 4y ago
I tend to memorize it like this:
If number modulus 3 is true, print "Fizz"
If number modulus 5 is true, print "Buzz"
If number modulus 15 is true, print "FizzBuzz"
My favorite examples are in Python and Lua, but I honestly adore Lua's version as it makes it really clear of what it does.
Here's an implementation of mine for reference:
local startTime = os.clock()
for i=1,100 do
fizz = (i % 3 == 0) and "fizz" or ""
buzz = (i % 5 == 0) and "buzz" or ""
if fizz == "" and buzz == "" then goto continue end
print(string.format("[%03d]: %s", i, fizz..buzz))
::continue::
end
local endTime = os.clock()
print(string.format("Total time %.6f seconds", endTime - startTime))