Yes, it could be done. The easiest way would be to alphabetically sort the letters in each dictionary entry, and then store those sorted letters, along with the word in its original form, in memory or a file. Then everytime you want to 'unscramble' a word, you would sort it the same way as the sorted dictionary file, and then search for that sorted form in the dictionary file. Everytime you found a match in the dictionary file, you would have a possibility for unscrambling the word.
Example:
(dictionary file)
EHLLO=HELLO
EEHRT=THERE
ENO=ONE
OTW=TWO
EEHRT=THREE
FORU=FOUR
EFIV=FIVE
ETHER=EEHRT
A 'scrambled' word, sorted:
RETHE -> EEHRT
Search through the dictionary file, possible matches:
THERE <- EEHRT
THREE <- EEHRT
ETHER <- EEHRT
Matches: there, three, ether
Here is a code that you can use to sort the letters within a single word:
alias sort {
tokenize 32 $$1-
var %s = $1
var %hname = $+(asort.,$ticks)
if ($hget(%hname)) hfree %hname
var %i = 0, %ii = $len(%s)
while (%i < %ii) {
inc %i
hadd -m %hname $+(s.,%i) $asc($mid(%s,%i,1))
}
var %x, %i = 0, %ii = $calc($len(%s) - 1)
while (%i < %ii) {
inc %i
%x = %i
var %j = %i, %jj = $calc(%ii + 1)
while (%j < %jj) {
inc %j
if ($hget(%hname,$+(s.,%x)) >= $hget(%hname,$+(s.,%j))) { %x = %j }
}
var %t = $hget(%hname,$+(s.,%i))
hadd %hname $+(s.,%i) $hget(%hname,$+(s.,%x))
hadd %hname $+(s.,%x) %t
}
var %ss, %i = 0, %ii = $len(%s)
while (%i < %ii) {
inc %i
%ss = $+(%ss,$chr($hget(%hname,$+(s.,%i))))
}
$iif($isid,return,echo -a) %ss
hfree %hname
}
Just loop through every word in your dictionary, and sort them with the above code. You will have to decide how you want to store the sorted dictionary so that it can be searched later. The easiest would be a txt file, as in my example above <SORTED>=<UNSORTED> . Then you can search the text file for all lines that begin with
SORTED= and then return the UNSORTED text after the = char.
-genius_at_work