Unique characters: Difference between revisions

Content added Content deleted
Line 945: Line 945:
unpack = unpack or table.unpack -- compatibility for all Lua versions
unpack = unpack or table.unpack -- compatibility for all Lua versions


local map = {}
for i, str in ipairs (strings) do
for i, str in ipairs (strings) do
local map = {}
for i=1, string.len(str) do
for i=1, string.len(str) do
local char = string.sub(str,i,i)
local char = string.sub(str,i,i)
Line 955: Line 956:
end
end
end
end
local list = {}
end
for char, bool in pairs (map) do

if bool then
table.insert (list, char)
local list = {}
for char, bool in pairs (map) do
end
if bool then
table.insert (list, char)
end
end
end
table.sort (list)
print (unpack (list))
table.sort (list)
end</lang>
print (unpack (list))</lang>
{{out}}<pre>
{{out}}<pre>1 5 6 b g s t z</pre>
1 5 a b c
6 a s t
d f g z</pre>


=={{header|Mathematica}}/{{header|Wolfram Language}}==
=={{header|Mathematica}}/{{header|Wolfram Language}}==