But with this code it take like 30sec to check the database, and also it use like 40% of shell cpu
Here is the code, if someone got an idea to make it faster, but maybe it is impossible with TCL ?
made fast comments to make it fast reading.
Code: Select all
proc read:scrab { } {
#Opening the db
if {![catch {set fileRead [open mydatabase r]}]} {
#Setting a var for counting
set count 0
#Launching a loop to read the file
while {![eof $fileRead]} {
#Checking each Words in db, and incr count if it fit with Letters
if {[checking [gets $fileRead]] == "1"} { incr count; }
}
return $count
close $fileRead
}
}
#Here is the code who compare Words & Letters
proc checking {arg} {
#Calling var ll who contain Letters from Scrabble
global ll
#Spliting var of Letters and Words to make them as lists
set Letters [split [string tolower $ll] ""]
set Word [split [string tolower $arg] ""]
#Launching a loop who'll compare each letter for Words one by one
for {set nb 0} {$nb<[llength $Word]} {incr nb} {
#Searching for a letter from $Word in $Letters
set sch [lsearch $Letters [lindex $Word $nb]]
#If the letter from $Word isin $Letters, then erase it, or get out
if {$sch >= "0"} { set temp [lreplace $Letters $sch $sch]; } else { return "-1"; }
}
#To confirm that the $Letters can construct the $Word
return "1"
}