tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
30
Task/Semordnilap/Tcl/semordnilap.tcl
Normal file
30
Task/Semordnilap/Tcl/semordnilap.tcl
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
package require Tcl 8.5
|
||||
package require http
|
||||
|
||||
# Fetch the words
|
||||
set t [http::geturl http://www.puzzlers.org/pub/wordlists/unixdict.txt]
|
||||
set wordlist [split [http::data $t] \n]
|
||||
http::cleanup $t
|
||||
|
||||
# Build hash table for speed
|
||||
foreach word $wordlist {
|
||||
set reversed([string reverse $word]) "dummy"
|
||||
}
|
||||
|
||||
# Find where a reversal exists
|
||||
foreach word $wordlist {
|
||||
if {[info exists reversed($word)] && $word ne [string reverse $word]} {
|
||||
# Remove to prevent pairs from being printed twice
|
||||
unset reversed([string reverse $word])
|
||||
# Add to collection of pairs
|
||||
set pairs($word/[string reverse $word]) "dummy"
|
||||
}
|
||||
}
|
||||
set pairlist [array names pairs] ;# NB: pairs are in *arbitrary* order
|
||||
|
||||
# Report what we've found
|
||||
puts "Found [llength $pairlist] reversed pairs"
|
||||
foreach pair $pairlist {
|
||||
puts "Example: $pair"
|
||||
if {[incr i]>=5} break
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue