aboutsummaryrefslogtreecommitdiff
path: root/challenge-333/hvukman/lua/333_p2.lua
blob: 7fe02a96b7e295667ab1579940e76e2a2021fb55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
-- insert in res while res<=x
function Dup2(x)
    local len = #x
    local res = {}
    for l,v in ipairs(x) do
        
        if v == 0 then
            table.insert(res,0)
            if #res >= len then break end
            table.insert(res,0)
        else 
            table.insert(res,v)
        end
        if #res >= len then break end
    end

    for k,m in ipairs(res) do
        io.write (m," ")
    end
    io.write ("\n")
end

Dup2({ 1; 0; 2; 3; 0; 4; 5; 0})
Dup2({ 1;2;3})
Dup2({ 1;2;3;0})
Dup2({ 0;0;1;2})
Dup2({ 1;2;0;3;4})