My friend Sperti is hosting a quiz-like game over at his weblog. He posts a question every friday night and additionally gives a number representing the position of a certain letter inside the answer string. Sperti is going to post eleven questions and if you’ve got all of them right you’ll be able to unscrabble the extracted letters to a word which will earn you an evening out in the viennese nightlife with the quizmaster himself paying for everything.
Inspiration enough for me to ensure I’m going to be this one lucky fella. So I thought about how my personal computer could ease the job. Unfortunately i came to the conclusion that I’d have to find the answers to the questions by myself but at least I found a computational way to do the unscrabbling of the letters by using GNU Aspell.
GNU Aspell is an open source spell checker which can be used independently or as a library like I did. I’ve written a command line tool in C which takes a sequence of letters as it’s argument, computes all possible permutations and matches each permutation against an Aspell dictionary. If the permutation matches a word in the dictionary it is written to the program’s stdout. It’s also possible to get guesses for “incomplete” scrabbles. This all is pretty straightforward but let me give you an example for each of those usecases anyway:
Thomas@thomas ~>unscrabble tmgicpnou
computing
Thomas@thomas ~>unscrabble -length 6 monm
Mormon
moment
Munmro
common
Thomas@thomas ~>unscrabble -lang de chinakreme
mechaniker
I suppose the first example doesn’t need any further explanation so let’s move on to the second one. The command line argument -length can be used in order to get guesses for an “incomplete” scrabble. In the example above we are searching for a word consisting of six characters whearas four of these characters are ‘m’, ‘m’, ‘o’ and ‘n’. Unscrabble gets suggestions from Aspell which focus lies on detecting spelling mistakes, not on solving scrabbles ;). Therefore the list of suggestions might not be complete. Aspell’s suggestion strategy is based on the Levenshtein distance and soundslike equivalents. Unscrabble filters all suggestions from Aspell that don’t meet the prior mentioned conditions and displays only those that do.
The third example demonstrates how to use non-english Aspell dictionaries. For that purpose it’s necessary to use the -lang option followed by the name of a valid installed dictionary. You can get a list of all installed Aspell dictionaries by executing the following command:
Thomas@thomas ~>aspell dump dicts
de
de_CH
de_DE
en
en_CA
en_CA-w-accents
en_GB
en_GB-w-accents
en_US
en_US-w-accents
These are the requirements for compiling the most valuable unix command line tool ever:
and this is how you do it:
Thomas@thomas ~>make unscrabble
gcc -o unscrabble -laspell unscrabble.c
i suggest not to unscrabble any words consisting of more than eleven characters unless you’ve got a whooole lot of time.
getting suggestions for incomplete scrabbles is even more computationally intensive.
unscrabble.tar.gz (1,53kb)