Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
20
Task/General-FizzBuzz/Lua/general-fizzbuzz-1.lua
Normal file
20
Task/General-FizzBuzz/Lua/general-fizzbuzz-1.lua
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
function genFizz (param)
|
||||
local response
|
||||
print("\n")
|
||||
for n = 1, param.limit do
|
||||
response = ""
|
||||
for i = 1, 3 do
|
||||
if n % param.factor[i] == 0 then
|
||||
response = response .. param.word[i]
|
||||
end
|
||||
end
|
||||
if response == "" then print(n) else print(response) end
|
||||
end
|
||||
end
|
||||
|
||||
local param = {factor = {}, word = {}}
|
||||
param.limit = io.read()
|
||||
for i = 1, 3 do
|
||||
param.factor[i], param.word[i] = io.read("*number", "*line")
|
||||
end
|
||||
genFizz(param)
|
||||
35
Task/General-FizzBuzz/Lua/general-fizzbuzz-2.lua
Normal file
35
Task/General-FizzBuzz/Lua/general-fizzbuzz-2.lua
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
local function fizzbuzz(n, mods)
|
||||
local res = {}
|
||||
|
||||
for i = 1, #mods, 2 do
|
||||
local mod, name = mods[i], mods[i+1]
|
||||
for i = mod, n, mod do
|
||||
res[i] = (res[i] or '') .. name
|
||||
end
|
||||
end
|
||||
|
||||
for i = 1, n do
|
||||
res[i] = res[i] or i
|
||||
end
|
||||
|
||||
return table.concat(res, '\n')
|
||||
end
|
||||
|
||||
do
|
||||
local n = tonumber(io.read()) -- number of lines, eg. 100
|
||||
local mods = {}
|
||||
|
||||
local n_mods = 0
|
||||
while n_mods ~= 3 do -- for reading until EOF, change 3 to -1
|
||||
local line = io.read()
|
||||
if not line then break end
|
||||
local s, e = line:find(' ')
|
||||
local num = tonumber(line:sub(1, s-1))
|
||||
local name = line:sub(e+1)
|
||||
mods[#mods+1] = num
|
||||
mods[#mods+1] = name
|
||||
n_mods = n_mods + 1
|
||||
end
|
||||
|
||||
print(fizzbuzz(n, mods))
|
||||
end
|
||||
30
Task/General-FizzBuzz/Lua/general-fizzbuzz-3.lua
Normal file
30
Task/General-FizzBuzz/Lua/general-fizzbuzz-3.lua
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#!/usr/bin/env luajit
|
||||
|
||||
local num = arg[1] or tonumber(arg[1]) or 110
|
||||
local t = {
|
||||
{3, "Fizz"},
|
||||
{5, "Buzz"},
|
||||
{7, "Gazz"},
|
||||
}
|
||||
|
||||
-- `cnt` contains counters for each factor-word pair; when a counter of a pair reaches its factor,
|
||||
-- the counter is reset to zero and the word is written to output
|
||||
local cnt = setmetatable({}, {__index = function() return 0 end})
|
||||
|
||||
for i = 1,num do
|
||||
for i = 1,#t do
|
||||
cnt[i] = cnt[i]+1
|
||||
end
|
||||
local match = false
|
||||
for i=1,#t do
|
||||
if cnt[i] == t[i][1] then
|
||||
io.write(t[i][2])
|
||||
cnt[i] = 0
|
||||
match = true
|
||||
end
|
||||
end
|
||||
if not match then
|
||||
io.write(i)
|
||||
end
|
||||
io.write(", ")
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue