Jump to content

General FizzBuzz: Difference between revisions

→‎{{header|Lua}}: Changed to reflect changes in the original (Python) version.
m (→‎{{header|Python}}: Removed unnecessary import and empty line; changed order in example output.)
(→‎{{header|Lua}}: Changed to reflect changes in the original (Python) version.)
Line 1,166:
'''One of the few solutions which do not use expensive modulo ''(think about the CPU!)''.'''
{{trans|Python}}
<lang Lua>local def_nn_def = 1008
local def_modsmods_def = {
[3] =, 'Fizzcheese ',
[5] =2, 'Buzzborccoli ',
3, 'sauce ',
}
 
local function fizzbuzz(n, mods)
n = n or def_nn_def
mods = #mods ~= 0 and mods or def_mods mods_def
 
local res = {}
 
for num,i name= in1, pairs(#mods), 2 do
forlocal imod, name = nummods[i], n, num domods[i+1]
for i = mod, n, mod do
res[i] = (res[i] or '') .. name
end
Line 1,196 ⟶ 1,198:
 
local n_mods = 0
while n_mods ~= 3-1 do -- for reading until EOF, change 3 to -1
local line = io.read()
if not line then break end
Line 1,202 ⟶ 1,204:
local num = tonumber(line:sub(1, s-1))
local name = line:sub(e+1)
mods[num#mods+1] = namenum
mods[#mods+1] = name
n_mods = n_mods + 1
end
Cookies help us deliver our services. By using our services, you agree to our use of cookies.