Sync
This commit is contained in:
parent
6f050a029e
commit
776bba907c
3887 changed files with 59894 additions and 7280 deletions
11
Task/Semordnilap/Icon/semordnilap.icon
Normal file
11
Task/Semordnilap/Icon/semordnilap.icon
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
procedure main(a)
|
||||
words := set()
|
||||
found := 0
|
||||
every word := map(!&input) do {
|
||||
if member(words, reverse(word)) then {
|
||||
if (found +:= 1) <= 5 then write("\t",reverse(word),"/",word)
|
||||
}
|
||||
else insert(words, word)
|
||||
}
|
||||
write("\nFound ",found," semordnilap words")
|
||||
end
|
||||
34
Task/Semordnilap/Lua/semordnilap.lua
Normal file
34
Task/Semordnilap/Lua/semordnilap.lua
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#!/usr/bin/env lua
|
||||
-- allow dictionary file and sample size to be specified on command line
|
||||
local dictfile = arg[1] or "unixdict.txt"
|
||||
local sample_size = arg[2] or 5;
|
||||
|
||||
-- read dictionary
|
||||
local f = assert(io.open(dictfile, "r"))
|
||||
local dict = {}
|
||||
for line in f:lines() do
|
||||
dict[line] = line:reverse()
|
||||
end
|
||||
f:close()
|
||||
|
||||
-- find the semordnilaps
|
||||
local semordnilaps = {}
|
||||
for fwd, rev in pairs(dict) do
|
||||
if dict[rev] and fwd < rev then
|
||||
table.insert(semordnilaps, {fwd,rev})
|
||||
end
|
||||
end
|
||||
|
||||
-- print the report
|
||||
print("There are " .. #semordnilaps .. " semordnilaps in " .. dictfile .. ". Here are " .. sample_size .. ":")
|
||||
|
||||
math.randomseed( os.time() )
|
||||
for i = 1, sample_size do
|
||||
local j
|
||||
repeat
|
||||
j = math.random(1,#semordnilaps)
|
||||
until semordnilaps[j]
|
||||
local f, r = unpack(semordnilaps[j])
|
||||
semordnilaps[j] = nil
|
||||
print(f .. " -> " .. r)
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue