Textonyms: Difference between revisions

1,950 bytes added ,  9 years ago
Tcl implementation added
(+ D entry)
(Tcl implementation added)
Line 1,132:
They require 22903 digit combinations to represent them.
1473 digit combinations represent Textonyms.</pre>
 
=={{header|Tcl}}==
 
<lang Tcl>set keymap {
2 -> ABC
3 -> DEF
4 -> GHI
5 -> JKL
6 -> MNO
7 -> PQRS
8 -> TUV
9 -> WXYZ
}
 
set url http://www.puzzlers.org/pub/wordlists/unixdict.txt
 
set report {
There are %1$s words in %2$s which can be represented by the digit key mapping.
They require %3$s digit combinations to represent them.
%4$s digit combinations represent Textonyms.
 
A %5$s-letter textonym which has %6$s combinations is %7$s:
 
%8$s
}
 
package require http
proc geturl {url} {
try {
set tok [http::geturl $url]
return [http::data $tok]
} finally {
http::cleanup $tok
}
}
 
proc main {keymap url} {
foreach {digit -> letters} $keymap {
foreach l [split $letters ""] {
dict set strmap $l $digit
}
}
set doc [geturl $url]
foreach word [split $doc \n] {
if {![string is alpha -strict $word]} continue
dict lappend words [string map $strmap [string toupper $word]] $word
}
 
set ncombos [dict size $words]
set nwords 0
set ntextos 0
set nmax 0
set dmax ""
dict for {d ws} $words {
puts [list $d $ws]
set n [llength $ws]
incr nwords $n
if {$n > 1} {
incr ntextos $n
}
if {$n >= $nmax && [string length $d] > [string length $dmax]} {
set nmax $n
set dmax $d
}
}
set maxwords [dict get $words $dmax]
set lenmax [llength $maxwords]
format $::report $nwords $url $ncombos $ntextos $lenmax $nmax $dmax $maxwords
}
 
puts [main $keymap $url]</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.
3548 digit combinations represent Textonyms.
 
A 6-letter textonym which has 6 combinations is 2253:
 
able bake bald bale cake calf
</pre>
 
=={{header|zkl}}==
Anonymous user