aboutsummaryrefslogtreecommitdiff
path: root/challenge-336/hvukman/lua/336_p1.lua
blob: 76bc6ac291924a31a648cba09c9749ea03196f42 (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
42
43
44
45
46
47
48
49
50
51
function gcd(x, y)
	if (y == 0) then
		return x
	else 
		return gcd(y, x%y)
	end
end

function Equal_group(x)
    
    local set ={}


    for i,v in ipairs(x) do
        set[v]=true
    end
    local res = {}
    for i,v in pairs(set) do
    --  print(i)
        local res_=0
        for _,w in ipairs(x) do
            if i==w then
            res_ =res_+ 1
            end
        end
        table.insert(res,res_)  
    end


    local dummy=0
    local valid = true
    for i=2,#res do
	    -- gcd for each pair
		dummy= gcd(res[i-1],res[i])
    --print (dummy)
	-- if gcd<=1 then failure
    if dummy <= 1 then
            valid = false
    end
    if valid == false then break end
    end

    print(valid)
end

local inputs = { {1,1,2,2,2,2},{1,1,1,2,2,2,3,3}, {5,5,5,5,5,5,7,7,7,7,7,7},{1,2,3,4},{8,8,9,9,10,10,11,11} }

for i=1,#inputs do
    Equal_group(inputs[i])
end