Textonyms: Difference between revisions
Content added Content deleted
MaiconSoft (talk | contribs) No edit summary |
(Added Wren) |
||
Line 2,874: | Line 2,874: | ||
They require 22903 digit combinations to represent them. |
They require 22903 digit combinations to represent them. |
||
1473 digit combinations represent Textonyms.</pre> |
1473 digit combinations represent Textonyms.</pre> |
||
=={{header|Wren}}== |
|||
{{trans|Kotlin}} |
|||
{{libheader|Wren-str}} |
|||
{{libheader|Wren-sort}} |
|||
{{libheader|Wren-fmt}} |
|||
<lang ecmascript>import "io" for File |
|||
import "/str" for Char, Str |
|||
import "/sort" for Sort |
|||
import "/fmt" for Fmt |
|||
var wordList = "unixdict.txt" |
|||
var DIGITS = "22233344455566677778889999" |
|||
var map = {} |
|||
var countValid = 0 |
|||
var words = File.read(wordList).trimEnd().split("\n") |
|||
for (word in words) { |
|||
var valid = true |
|||
var sb = "" |
|||
for (c in Str.lower(word)) { |
|||
if (!Char.isLower(c)) { |
|||
valid = false |
|||
break |
|||
} |
|||
sb = sb + DIGITS[Char.code(c) - 97] |
|||
} |
|||
if (valid) { |
|||
countValid = countValid + 1 |
|||
if (map.containsKey(sb)) { |
|||
map[sb].add(word) |
|||
} else { |
|||
map[sb] = [word] |
|||
} |
|||
} |
|||
} |
|||
var textonyms = map.toList.where { |me| me.value.count > 1 }.toList |
|||
var report = "There are %(countValid) words in '%(wordList)' " + |
|||
"which can be represented by the digit key mapping.\n" + |
|||
"They require %(map.count) digit combinations to represent them.\n" + |
|||
"%(textonyms.count) digit combinations represent Textonyms.\n" |
|||
System.print(report) |
|||
var longest = Sort.merge(textonyms) { |i, j| (j.key.count - i.key.count).sign } |
|||
var ambiguous = Sort.merge(longest) { |i, j| (j.value.count - i.value.count).sign } |
|||
System.print("Top 8 in ambiguity: \n") |
|||
System.print("Count Textonym Words") |
|||
System.print("====== ======== =====") |
|||
var f = "$4d $-8s $s" |
|||
for (a in ambiguous.take(8)) Fmt.print(f, a.value.count, a.key, a.value) |
|||
f = f.replace("8", "14") |
|||
System.print("\nTop 6 in length:\n") |
|||
System.print("Length Textonym Words") |
|||
System.print("====== ============== =====") |
|||
for (l in longest.take(6)) Fmt.print(f, l.key.count, l.key, l.value)</lang> |
|||
{{out}} |
|||
<pre> |
|||
There are 24978 words in '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 269 amy any bmw bow box boy cow cox coy |
|||
9 729 paw pax pay paz raw ray saw sax say |
|||
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|zkl}}== |
=={{header|zkl}}== |