General FizzBuzz: Difference between revisions

Content deleted Content added
→‎{{header|Lua}}: Changed to reflect changes in the original (Python) version.
→‎{{header|Lua}}: Removed default values, added output.
Line 1,166: Line 1,166:
'''One of the few solutions which do not use expensive modulo ''(think about the CPU!)''.'''
'''One of the few solutions which do not use expensive modulo ''(think about the CPU!)''.'''
{{trans|Python}}
{{trans|Python}}
<lang Lua>local n_def = 8
<lang Lua>local function fizzbuzz(n, mods)
local mods_def = {
3, 'cheese ',
2, 'borccoli ',
3, 'sauce ',
}

local function fizzbuzz(n, mods)
n = n or n_def
mods = #mods ~= 0 and mods or mods_def

local res = {}
local res = {}


Line 1,212: Line 1,202:
end
end
</lang>
</lang>

{{out}}
<pre>
> mods = {
>> 3, 'cheese ',
>> 2, 'broccoli ',
>> 3, 'sauce ',
>> }
> fizzbuzz(8, mods)
1
broccoli
cheese sauce
broccoli
5
cheese broccoli sauce
7
broccoli </pre>


=={{header|Nim}}==
=={{header|Nim}}==