diff options
| author | 冯昶 <fengchang@novel-supertv.com> | 2023-11-13 10:15:17 +0800 |
|---|---|---|
| committer | 冯昶 <fengchang@novel-supertv.com> | 2023-11-13 10:15:17 +0800 |
| commit | 41f99d3c168e8def8c2a799c592282acf0d275a8 (patch) | |
| tree | e862f32c73ecc3b39546d8f2e40268097bdc84eb /challenge-127/deadmarshal/lua/ch-1.lua | |
| parent | 9831ad5b94643aec63e30e720b83dff7a5eac18b (diff) | |
| parent | f4d46d9aa21b95dbb99eec92f338d157273fbbdb (diff) | |
| download | perlweeklychallenge-club-41f99d3c168e8def8c2a799c592282acf0d275a8.tar.gz perlweeklychallenge-club-41f99d3c168e8def8c2a799c592282acf0d275a8.tar.bz2 perlweeklychallenge-club-41f99d3c168e8def8c2a799c592282acf0d275a8.zip | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-127/deadmarshal/lua/ch-1.lua')
| -rw-r--r-- | challenge-127/deadmarshal/lua/ch-1.lua | 19 |
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})) + |
