Textonyms: Difference between revisions

Added Kotlin
(Added Kotlin)
Line 1,175:
7217 (10) PA's, PC's, Pa's, Pb's, Ra's, Rb's, SC's, Sb's, Sc's, pa's
4317 (10) GE's, Gd's, Ge's, HF's, He's, Hf's, ID's, he's, id's, if's
</pre>
 
=={{header|Kotlin}}==
<lang scala>// version 1.1.4-3
 
import java.io.File
 
val wordList = "unixdict.txt"
val url = "http://www.puzzlers.org/pub/wordlists/unixdict.txt"
 
const val DIGITS = "22233344455566677778889999"
 
val map = mutableMapOf<String, MutableList<String>>()
 
fun processList() {
var countValid = 0
val f = File(wordList)
val sb = StringBuilder()
 
f.forEachLine { word->
var valid = true
sb.setLength(0)
for (c in word.toLowerCase()) {
if (c !in 'a'..'z') {
valid = false
break
}
sb.append(DIGITS[c - 'a'])
}
if (valid) {
countValid++
val key = sb.toString()
if (map.containsKey(key)) {
map[key]!!.add(word)
}
else {
map.put(key, mutableListOf(word))
}
}
}
var textonyms = map.filter { it.value.size > 1 }.toList()
val report = "There are $countValid words in '$url' " +
"which can be represented by the digit key mapping.\n" +
"They require ${map.size} digit combinations to represent them.\n" +
"${textonyms.size} digit combinations represent Textonyms.\n"
println(report)
 
val length = textonyms.sortedByDescending { it.first.length }
val ambiguous = length.sortedByDescending { it.second.size }
 
println("Top 8 in ambiguity:\n")
println("Count Textonym Words")
println("====== ======== =====")
var fmt = "%4d %-8s %s"
for (a in ambiguous.take(8)) println(fmt.format(a.second.size, a.first, a.second))
 
fmt = fmt.replace("8", "14")
println("\nTop 6 in length:\n")
println("Length Textonym Words")
println("====== ============== =====")
for (l in length.take(6)) println(fmt.format(l.first.length, l.first, l.second))
}
 
fun main(args: Array<String>) {
processList()
}</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 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 426 [gam, gao, ham, han, ian, ibm, ibn]
7 782 [pta, pub, puc, pvc, qua, rub, sub]
 
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>
 
9,490

edits