21 lines
703 B
Text
21 lines
703 B
Text
local file = io.open("unixdict.txt", "r")
|
|
local wmap = {}
|
|
for word in file:lines() do wmap[word] = true end
|
|
local pairs = {}
|
|
local used = {}
|
|
file:seek("set")
|
|
for word in file:lines() do
|
|
if word != "" then
|
|
local pal = string.reverse(word)
|
|
if word != pal and wmap[pal] and !used[pal] then
|
|
pairs:insert({word, pal})
|
|
used[word] = true
|
|
end
|
|
end
|
|
end
|
|
file:close()
|
|
print($"There are {#pairs} unique semordnilap pairs in the dictionary.")
|
|
print("\nIn sorted order, the first five are:")
|
|
for i = 1, 5 do print($" {pairs[i][1]}, {pairs[i][2]}") end
|
|
print("\nand the last five are:")
|
|
for i = #pairs - 4, #pairs do print($" {pairs[i][1]}, {pairs[i][2]}") end
|