In a message dated Fri, 7 Mar 2003, Warren Pollans writes:

> I would like to build a "scrabble/crossword_puzzle cheater".
>
> I think I want to do this by generating lists of words to choose from.
> For example, I'd eventually like to be able to do the following:
>
>       list all n-letter, with N1 < n < N2, words with 'a' as the 2nd
> letter and 'z' as the 6th
>
>
> I'm not looking for a solution - just a suggestion about how to generate
> the word lists I want.  Of course, if this has already been done, please
> point me to it :-)

You don't need anything other than a command line for this, at least in
the case of a crossword.  egrep will work fine, like this (assuming that n
was 6):

  # egrep '^.a...z$' /usr/share/dict/words
  halerz
  halutz
  paletz
  Tabriz
  tafwiz

A Perl solution that would allow a tiny bit less typing would be as simple
as

  #!/usr/bin/perl -wn
  BEGIN {
     $pat = "[EMAIL PROTECTED]";
     $pat =~ s/\s//g;
     @ARGV = qw(/usr/share/dict/words)
  }
  print if /$pat/;

(Or much simpler if you didn't want it to be as user-friendly.)  And then
you could just call it as

  $ findword .a...z

But this would be a bit slower than egrep.  My suggested solution for this
would be to write a shell function or alias for your preferred shell that
just calls egrep on /usr/share/dict/words.

A scrabble solution would be a bit more difficult, and you'd want to go
into Perl or other language of choice.  You'd probably need to play with a
few different algorithms, to see which performed best--though I'm certain
somebody's analyzed this problem before, so some research might turn up
something you could use.

Off the top of my head, one approach would be to generate regexes with
repeating character classes matching the tiles in your hand, like so:

  # Tiles are 'a', 'b', 'c'
  $pat = qr/^[abc]{1,3}$/;

match them all against words, and then cull through the results to see
which are possible to construct with your hand, given number of repeating
tiles, etc.  (Dealing with Qu and wildcard would require some finesse.)
This would likely be slower than a more nuanced approach, but it might be
fast enough--and who cares about the computer's time?  Yours is more
important.  (This is the mantra of many Perl programmers.)

Trey

Reply via email to