Cheating At Scrabble
Finding out what words you can form with your letters
OK, was having a discussion with Matt's brother Dan and we verbally walked through a method of cheating at scrabble using a computer.
Generally you want something like this from the command line:
Now, the following will work:
If you want to know what words you can form with the letters in your hand, then something like this will work
Gives the following output:
Say I had the following hand: A D E F G I M N and I wanted to see all words that didn't duplicate any of those letters:
The second pattern looks for any pattern with one of the letters, followed by any number of characters (including 0 characters) followed by the same letter as original. This is equivalent to making sure there aren't any duplicates.
Say we're playing scrabble with the following board
And you wanted to know the largest word possible that fit into the first row. You can use a regex like the following (assuming the same hand as above):
So the first expression finds words only made up of the letters we have. The second expression filters out duplicates for the letters other than E. The third expression allows any word either starting with E or having E as the second letter.
Finding out what your word is worth
Putting it all together
So for chuckles, lets look at that last example again and see what the best word we could form would be:
So defaming will be our optimal word in this particular case.
You could obviously enhance the sample code above to craft yourself a robot that would look at a given scrabble board and find the optimal word placement... that's beyond the scope of this document and will be left as an exercise to the motivated reader!