Textonyms: Difference between revisions
Content added Content deleted
Alextretyak (talk | contribs) (Added 11l) |
|||
Line 2,004: | Line 2,004: | ||
They require 22908 digit combinations to represent them. |
They require 22908 digit combinations to represent them. |
||
1473 digit combinations represent Textonyms.</pre> |
1473 digit combinations represent Textonyms.</pre> |
||
=={{header|Nim}}== |
|||
{{trans|Kotlin}} |
|||
<lang Nim>import algorithm, sequtils, strformat, strutils, tables |
|||
const |
|||
WordList = "unixdict.txt" |
|||
Url = "http://www.puzzlers.org/pub/wordlists/unixdict.txt" |
|||
Digits = "22233344455566677778889999" |
|||
proc processList(wordFile: string) = |
|||
var mapping: Table[string, seq[string]] |
|||
var countValid = 0 |
|||
for word in wordFile.lines: |
|||
var valid = true |
|||
var key: string |
|||
for c in word.toLowerAscii: |
|||
if c notin 'a'..'z': |
|||
valid = false |
|||
break |
|||
key.add Digits[ord(c) - ord('a')] |
|||
if valid: |
|||
inc countValid |
|||
mapping.mgetOrPut(key, @[]).add word |
|||
let textonyms = toSeq(mapping.pairs).filterIt(it[1].len > 1) |
|||
echo &"There are {countValid} words in '{Url}' ", |
|||
&"which can be represented by the digit key mapping." |
|||
echo &"They require {mapping.len} digit combinations to represent them." |
|||
echo &"{textonyms.len} digit combinations represent Textonyms.\n" |
|||
let longest = textonyms.sortedByIt(-it[0].len) |
|||
let ambiguous = longest.sortedByIt(-it[1].len) |
|||
echo "Top 8 in ambiguity:\n" |
|||
echo "Count Textonym Words" |
|||
echo "====== ======== =====" |
|||
for a in ambiguous[0..7]: |
|||
echo &"""{a[1].len:4} {a[0]:>8} {a[1].join(", ")}""" |
|||
echo "\nTop 6 in length:\n" |
|||
echo "Length Textonym Words" |
|||
echo "====== ============== =====" |
|||
for l in longest[0..5]: |
|||
echo &"""{l[0].len:4} {l[0]:>14} {l[1].join(", ")}""" |
|||
processList(WordList)</lang> |
|||
{{out}} |
|||
<pre>There are 24978 words in 'http://www.puzzlers.org/pub/wordlists/unixdict.txt' which can be represented by the digit key mapping. |
|||
They require 22903 digit combinations to represent them. |
|||
1473 digit combinations represent Textonyms. |
|||
Top 8 in ambiguity: |
|||
Count Textonym Words |
|||
====== ======== ===== |
|||
9 729 paw, pax, pay, paz, raw, ray, saw, sax, say |
|||
9 269 amy, any, bmw, bow, box, boy, cow, cox, coy |
|||
8 2273 acre, bard, bare, base, cape, card, care, case |
|||
8 726 pam, pan, ram, ran, sam, san, sao, scm |
|||
7 4663 gone, good, goof, home, hone, hood, hoof |
|||
7 7283 pate, pave, rate, rave, saud, save, scud |
|||
7 782 pta, pub, puc, pvc, qua, rub, sub |
|||
7 426 gam, gao, ham, han, ian, ibm, ibn |
|||
Top 6 in length: |
|||
Length Textonym Words |
|||
====== ============== ===== |
|||
14 25287876746242 claustrophobia, claustrophobic |
|||
13 7244967473642 schizophrenia, schizophrenic |
|||
12 666628676342 onomatopoeia, onomatopoeic |
|||
11 49376746242 hydrophobia, hydrophobic |
|||
10 2668368466 contention, convention |
|||
10 6388537663 mettlesome, nettlesome</pre> |
|||
=={{header|Perl}}== |
=={{header|Perl}}== |