I think that using a regexp to solve this is using a sledgehammer to crack a nut. It can be done easily for problem (1) as long as the regexp packge you use allows for numbered repetition counts, eg "a(7)" meaning 0 to 7 letter a's. You'ld need to presort the word before testing it.

The obvious implementation using an array of letter counts will be faster and more elegant. (A regexp solution may well mean shorter source code, but that equates with elegance only if you ignore what it's doing behind the scenes...)

I'm reasonably sure that a regexp solution allowing for two blanks will explode in size.

By the way on (3) there are two classic solutions that will be hard to beat: a) use a DAWG (Directed Acyclic Word Graph) or depending on space/speed requirements, one of the tweaked versions of same; and b) use an 'anagram dictionary' where your wordlist is keyed by an alpha sort of the letters, eg 'elpr => perl' in combination with a permutation generator.

If you can come up with anything new I'll be happy to list the code on the wordgame-programmers web site :-)

regards

Graham Toal (www.gtoal.com/wordgames/scrabble.html)


In reply to Re: Scrabble Word Regex Challenge by Anonymous Monk
in thread Scrabble Word Regex Challenge by QM

Title:
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, details, 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, summary, 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.