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
|
local inp = {{ "bella", "label", "roller" }, { "cool", "lock", "cook" } , { "hello", "world", "pole"}
, { "abc", "def", "ghi" }, { "aab", "aac", "aaa"}}
function Common(X)
local unique = {}
for i,v in ipairs(X) do
for j=1,#v do
local sub = string.sub(v,j,j)
unique[sub] = true
end
end
local res = {}
io.write ("Output: ")
-- check each unique character
for i,_ in pairs(unique) do
local res = {}
for _,v in ipairs(X) do
local sum =0
for index in (v):gmatch(i) do
sum = sum + 1
-- print("index ", index)
end
if sum>0 then
table.insert(res,sum)
end
end
if #res==3 then
table.sort(res)
for jj=1,res[1] do
io.write (i," ")
end
end
end
print("")
end
for i,v in ipairs(inp) do
Common(v)
end
|