September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
63
Task/Textonyms/Kotlin/textonyms.kotlin
Normal file
63
Task/Textonyms/Kotlin/textonyms.kotlin
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
// 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 longest = textonyms.sortedByDescending { it.first.length }
|
||||
val ambiguous = longest.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 longest.take(6)) println(fmt.format(l.first.length, l.first, l.second))
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
processList()
|
||||
}
|
||||
63
Task/Textonyms/Phix/textonyms.phix
Normal file
63
Task/Textonyms/Phix/textonyms.phix
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
sequence digit = repeat(-1,255)
|
||||
digit['a'..'c'] = '2'
|
||||
digit['d'..'f'] = '3'
|
||||
digit['g'..'i'] = '4'
|
||||
digit['j'..'l'] = '5'
|
||||
digit['m'..'o'] = '6'
|
||||
digit['p'..'s'] = '7'
|
||||
digit['t'..'v'] = '8'
|
||||
digit['w'..'z'] = '9'
|
||||
|
||||
function digits(string word)
|
||||
for i=1 to length(word) do
|
||||
integer ch = word[i]
|
||||
if ch<'a' or ch>'z' then return "" end if
|
||||
word[i] = digit[ch]
|
||||
end for
|
||||
return word
|
||||
end function
|
||||
|
||||
sequence words = {}, last=""
|
||||
object word, keycode
|
||||
integer keycode_count = 0, textonyms = 0,
|
||||
this_count = 0, max_count = 0, max_idx
|
||||
|
||||
integer fn = open("demo\\unixdict.txt","r")
|
||||
while 1 do
|
||||
word = trim(gets(fn))
|
||||
if atom(word) then exit end if
|
||||
keycode = digits(word)
|
||||
if length(keycode) then
|
||||
words = append(words, {keycode, word})
|
||||
end if
|
||||
end while
|
||||
close(fn)
|
||||
printf(1,"There are %d words in unixdict.txt which can be represented by the digit key mapping.\n",{length(words)})
|
||||
|
||||
words = sort(words)
|
||||
for i=1 to length(words) do
|
||||
{keycode,word} = words[i]
|
||||
if keycode=last then
|
||||
textonyms += this_count=1
|
||||
this_count += 1
|
||||
if this_count>max_count then
|
||||
max_count = this_count
|
||||
max_idx = i
|
||||
end if
|
||||
else
|
||||
keycode_count += 1
|
||||
last = keycode
|
||||
this_count = 1
|
||||
end if
|
||||
end for
|
||||
|
||||
printf(1,"They require %d digit combinations to represent them.\n",{keycode_count})
|
||||
printf(1,"%d digit combinations represent Textonyms.\n",{textonyms})
|
||||
|
||||
sequence dups = {}
|
||||
for i=max_idx-max_count+1 to max_idx do
|
||||
dups = append(dups,words[i][2])
|
||||
end for
|
||||
|
||||
printf(1,"The maximum number of textonyms for a particular digit key mapping is %d:\n",{max_count})
|
||||
printf(1," %s encodes %s\n",{words[max_idx][1],join(dups,"/")})
|
||||
30
Task/Textonyms/Zkl/textonyms.zkl
Normal file
30
Task/Textonyms/Zkl/textonyms.zkl
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
URL:="http://www.puzzlers.org/pub/wordlists/unixdict.txt";
|
||||
var ZC=Import("zklCurl");
|
||||
var keypad=Dictionary(
|
||||
"a",2,"b",2,"c",2, "d",3,"e",3,"f",3, "g",4,"h",4,"i",4,
|
||||
"j",5,"k",5,"l",5, "m",6,"n",6,"o",6, "p",7,"q",7,"r",7,"s",7,
|
||||
"t",8,"u",8,"v",8, "w",9,"x",9,"y",9,"z",9);
|
||||
//fcn numerate(word){ word.toLower().apply(keypad.find.fp1("")) }
|
||||
fcn numerate(word){ word.toLower().apply(keypad.get) } //-->textonym or error
|
||||
println("criticisms --> ",numerate("criticisms"));
|
||||
|
||||
words:=ZC().get(URL); //--> T(Data,bytes of header, bytes of trailer)
|
||||
words=words[0].del(0,words[1]); // remove HTTP header
|
||||
println("Read %d words from %s".fmt(words.len(1),URL));
|
||||
|
||||
wcnt:=Dictionary();
|
||||
foreach word in (words.walker(11)){ // iterate over stripped lines
|
||||
w2n:=try{ numerate(word) }catch(NotFoundError){ continue };
|
||||
wcnt.appendV(w2n,word); // -->[textonym:list of words]
|
||||
}
|
||||
|
||||
moreThan1Word:=wcnt.reduce(fcn(s,[(k,v)]){ s+=(v.len()>1) },0);
|
||||
maxWordPerNum:=(0).max(wcnt.values.apply("len"));
|
||||
|
||||
("There are %d words which can be represented by the Textonyms mapping.\n"
|
||||
"There are %d overlaps.").fmt(wcnt.len(),moreThan1Word).println();
|
||||
|
||||
println("Max collisions: %d words:".fmt(maxWordPerNum));
|
||||
foreach k,v in (wcnt.filter('wrap([(k,v)]){ v.len()==maxWordPerNum })){
|
||||
println(" %s is the textonym of: %s".fmt(k,v.concat(", ")));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue