aboutsummaryrefslogtreecommitdiff
path: root/challenge-127/deadmarshal/lua/ch-1.lua
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-127/deadmarshal/lua/ch-1.lua')
-rw-r--r--challenge-127/deadmarshal/lua/ch-1.lua19
1 files changed, 19 insertions, 0 deletions
diff --git a/challenge-127/deadmarshal/lua/ch-1.lua b/challenge-127/deadmarshal/lua/ch-1.lua
new file mode 100644
index 0000000000..ae46729725
--- /dev/null
+++ b/challenge-127/deadmarshal/lua/ch-1.lua
@@ -0,0 +1,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}))
+