Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
53
Task/Textonyms/Pluto/textonyms.pluto
Normal file
53
Task/Textonyms/Pluto/textonyms.pluto
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
local fmt = require "fmt"
|
||||
|
||||
$define DIGITS = "22233344455566677778889999"
|
||||
|
||||
local word_list = "unixdict.txt"
|
||||
local map = {}
|
||||
local count_valid = 0
|
||||
local nl = os.platform == "windows" ? "\r\n" : "\n"
|
||||
local words = io.contents(word_list):rstrip():split(nl)
|
||||
for words as word do
|
||||
local valid = true
|
||||
local sb = ""
|
||||
local lword = word:lower()
|
||||
for i = 1, #lword do
|
||||
local c = lword[i]
|
||||
if not("a" <= c <= "z") then
|
||||
valid = false
|
||||
break
|
||||
end
|
||||
sb ..= DIGITS[c:byte() - 96]
|
||||
end
|
||||
if valid then
|
||||
count_valid += 1
|
||||
if map[sb] then
|
||||
map[sb]:insert(word)
|
||||
else
|
||||
map[sb] = {word}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local t = map:filtered(|v| -> #v > 1)
|
||||
local textonyms = t:keys():map(|k| -> {k, t[k]})
|
||||
local report = $"There are {count_valid} words in '{word_list}' " ..
|
||||
"which can be represented by the digit key mapping.\n" ..
|
||||
$"They require {#map:keys()} digit combinations to represent them.\n" ..
|
||||
$"{#textonyms} digit combinations represent Textonyms.\n"
|
||||
print(report)
|
||||
|
||||
local longest = textonyms:sorted(|i, j| -> #j[1] < #i[1])
|
||||
local ambiguous = longest:sorted(|i, j| -> #j[2] < #i[2])
|
||||
|
||||
print("Top 8 in ambiguity: \n")
|
||||
print("Count Textonym Words")
|
||||
print("====== ======== =====")
|
||||
local f = "%4d %-8s %s"
|
||||
for ambiguous:slice(1, 8) as a do fmt.print(f, #a[2], a[1], a[2]:concat(" ")) end
|
||||
|
||||
f = f:replace("8", "14")
|
||||
print("\nTop 6 in length:\n")
|
||||
print("Length Textonym Words")
|
||||
print("====== ============== =====")
|
||||
for longest:slice(1, 6) as l do fmt.print(f, #l[1], l[1], l[2]:concat(" ")) end
|
||||
Loading…
Add table
Add a link
Reference in a new issue