aboutsummaryrefslogtreecommitdiff
path: root/challenge-337/hvukman/lua/337_p2.lua
blob: 4a04e3664777100ad8520d3a2a8f864b89c316e4 (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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
function oddmatrix(row,col,locs)

    local mat = {}
    for i=1,row do
        mat[i]={}
        for j=1,col do
            mat[i][j]=0
        end
    end

    for i,v in ipairs(locs) do
      
        -- apply to rows
        for k=1,col do
            mat[v[1]+1][k]=mat[v[1]+1][k]+1
        end
        -- apply to cols
        for l=1,row do
            mat[l][v[2]+1] =  mat[l][v[2]+1]+1
        end

    end


    local odds=0

    for i=1,row do
        for j=1,col do
            if mat[i][j]%2~=0 then
                odds = odds + 1
            end
        end
    end
    print("odds ", odds)
end

oddmatrix(2,3,{{0,1},{1,1}})
oddmatrix(2,2,{{1,1},{0,0}})
oddmatrix(3,3,{{0,0},{1,2},{2,1}})
oddmatrix(1,5,{{0,2},{0,4}})
oddmatrix(4,2,{{1,0},{3,1},{2,0},{0,1}})