aboutsummaryrefslogtreecommitdiff
path: root/challenge-127/deadmarshal/lua/ch-1.lua
blob: ae467297259b2bb2c48c82d723df3a25d920d41c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/env lua

local function disjoint_sets(t1,t2)
  assert(type(t1) == 'table' and
	 type(t2) == 'table','t1,t2 must be tables!')
  local h = {}
  for i=1,#t1 do
    h[t1[i]] = (h[t1[i]] or 0) + 1
    h[t2[i]] = (h[t2[i]] or 0) + 1
  end
  for _,v in pairs(h) do
    if v > 1 then return false end
  end
  return true
end

print(disjoint_sets({1,2,5,3,4},{4,6,7,8,9}))
print(disjoint_sets({1,3,5,7,9},{0,2,4,6,8}))