Welcome to the Monastery PerlMonks

### Re: Word Unscrambler

by hossman (Prior)
 on Dec 17, 2005 at 08:49 UTC ( #517449=note: print w/replies, xml ) Need Help??

in reply to Word Unscrambler

I did something similar a few years back. I found that the biggest speed boost came from partitioning the dictionary in advance - making a sepearte file for each word length (ie: 1.letter.words, 2.letter.words, 3.letter.words, etc...) so you don't have to loop over words that obviously don't match.

It's obviously not worth it if you're just going to run it once, but if you this is somehting you plan on doing again and again...

Another approach I've had good luck with on a different type of word problem was to divide the dictionary up based on the first character in each word. That wouldn't help in your case, but a varient would...

Assuming your dictionary looks like this...

at
bat
cat
car
tab


...reformat it so it looks like this...

abt    bat
abt    tab
acr    car
act    cat
at     at


...then when you get a scrabbled word, sort the letters, and look it up (straight substring match, no regex needed) to find all the matches. To decrease the search space, you can partition the dictionary by first letter of the "word" (first letter when the letters are sorted that is) or by the length of the words, or by both.

Replies are listed 'Best First'.
Re^2: Word Unscrambler
by Anonymous Monk on Feb 05, 2009 at 00:00 UTC
uscramble, lateptrincne

Create A New User
Node Status?
node history
Node Type: note [id://517449]
help
Chatterbox?
 erix . o O( "what fools the french are, Jeeves" ) [choroba]: Also some Достое́вс кий [Discipulus]: mmh windows understand something like: cd c:\\\\path\\\\to weird.. [Discipulus]: even with odd number of \

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (9)
As of 2017-05-24 08:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
My favorite model of computation is ...

Results (183 votes). Check out past polls.