Here’s an updated version that shows the scrabble value of the words matching the letters.
function setup()
-- scrabble value of the letters a thru z
valTab={1,3,3,2,1,4,2,4,1,8,5,1,3,1,1,3,10,1,1,1,1,4,4,8,4,10}
local letters="tienvofxs" -- upper/lower case of letters must match case of dictionary
local st={}
for z=1,#letters do
table.insert(st,string.sub(letters,z,z))
end
table.sort(st)
-- read a dictionary file and create a dict table of words
local dict={}
dict={"one","two","three","four","five","six","seven","eight","nine","ten"}
foundTab={}
for z=1,#dict do
find(dict[z],st)
end
print("letters = "..letters)
print("words that match some letters")
print(table.concat(foundTab,"\
"))
end
function find(d,s)
if #d>#s then
return
end
local dt={}
for z=1,#d do
table.insert(dt,string.sub(d,z,z))
end
table.sort(dt)
local pos=1
for z=1,#dt do
if pos>#s then
return
end
for y=pos,#s do
if dt[z]==s[y] then
pos=y+1
break
elseif dt[z]>s[y] then
if y>=#s then
return
end
else
return
end
end
end
table.insert(foundTab,d.." "..getValue(d))
end
function getValue(word)
local tot=0
for z=1,#word do
tot=tot+valTab[string.byte(string.sub(word,z,z))-string.byte("a")+1]
end
return tot
end