Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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...


...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.

In reply to Re: Word Unscrambler by hossman
in thread Word Unscrambler by jonnybe

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (3)
    As of 2018-01-23 06:53 GMT
    Find Nodes?
      Voting Booth?
      How did you see in the new year?

      Results (240 votes). Check out past polls.