## Algebraic Crosswords

April 24, 2011

A blogger by the name of T Campbell recently posted an interesting read about Algebraic Crosswords. And at the end, T posts a \$100 bounty for a computer program to help crossword constructors construct such crosswords. That’s right up my alley as both a programmer and a puzzle solver, so I threw together a quick Python script to do the job.

My program, named algxword, can be downloaded from my GitHub.

The usage is as follows:

Usage: ./algxword.py [OPTIONS...] WORDLIST FROM TO

Finds all words in the file WORDLIST (which need not be sorted) which would
continue to be words when substituting the substring FROM for the substring TO.
Only words which contain FROM in them are considered.

Both FROM and TO can be empty strings.  If FROM is the empty string, then TO is
added at each position in the string to test for a word.  If TO is the empty
string, then the FROM string is simply deleted.

Ordinarily, only the first occurrence of FROM is replaced with TO.  If the -a
option is specified, then all occurrences of FROM are replaced with TO.

OPTIONS:

-a      Replaces all occurrences of FROM with TO when testing for a word
--help  Prints this help message

Examples:

# Find all words which remain words when substituting the first occurrence of
# 'qu' for 'k' in the word list /usr/share/dict/words
python algxword.py /usr/share/dict/words qu k

# Same as above, but replace all occurrences of 'qu' for 'k'
python algxword.py -a /usr/share/dict/words qu k

# Find all words which can have an 'lax' inserted in them
python algxword.py /usr/share/dict/words "" lax

More detailed instructions for the less command line-savvy can be found in the included README file.

UPDATE 2013-01-01:

The download location has been moved to GitHub. I also relicensed it under a BSD-like license instead of the GNU GPL.

### 5 Responses to “Algebraic Crosswords”

I’ve got Python (Windows x86 MSI Installer (2.7.1)) on my machine now, but I’m not sure how to invoke your program. When I double-click on algxword.py I get a flash of something, but it’s gone before I have time to read it. Can you help?

2. Hi Patrick,

First open up a command prompt by choosing “Run” from the Start Menu and typing in “cmd”. Then, navigate to where you unzipped algxword.py by typing:

cd \path\to\folder

(Replace “\path\to\folder” with the full path to the folder where you unzipped it).

Then, you should be able to run the program by typing any of the examples above into the command line. If you get an error message like “python is not recognized as an internal or external command, operable program or batch file.”, then you need to either specify the full filename to Python executable, or add Python to your Path environment variable (this page, particularly the section under the “Finding python.exe” heading, has instructions on how to do the latter).

This example uses the full path to the Python executable:

\Program Files\Python 2.7.1\python.exe algxword.py dictionary.txt qu k

I realize this is not a very friendly process for people who don’t ordinarily use the command line; if there’s a demand, I could put together a more user-friendly GUI version.

3. This looks really cool. I’ll give it a look.

I’ve been coding these up myself in perl — but with a different script for every application. This will be better.

4. Also — instead of writing a GUI, wouldn’t it be easier to make a web app to call the script?

5. Oh, what the hell, I made a web version myself. Adam, if you have any objections, let me know.