Creating a crossword puzzle

Dieser Post wurde aus meiner alten WordPress-Installation importiert. Sollte es Darstellungsprobleme, falsche Links oder fehlende Bilder geben, bitte einfach hier einen Kommentar hinterlassen. Danke.

Actually not a 100% real one, but something near by, like this one (near the end of the text).

Crossword puzzle creators must know and remember many words, but everybody could create one with a little help by a computer.

Things you need

  1. A spreadsheet tool like Google Documents, Microsoft Office or LibreOffice (the famous OpenOffice freed from Oracle)
  2. myspell language files (Ubuntu packages like myspell-de-de)
  3. Perl

Prepare the grid

Put a single letter into a random cell, "Select all" (by clicking on the top left blank part left of "A" and top of "1" or by pressing Ctrl+A) and resize all cells to have nearly the same (visible) width as height (by resizing one cell, all others will follow) and change the font size until the single letter fits the whole cell (no need to be exact). Remove the test letter when done.

Start somewhere in the middle of your screen and write down a (longer) word of your choice, one letter per cell. Add one or more words parallel (2-5 cells distance) and add anything which comes into your mind connecting those words.

Open a shell window and convert the myspell dictionary file for your language to a searchable list:

perl -ple 's/\/.+$//;' /usr/share/myspell/dicts/de?DE.dic |sort -u >de.dic
This line reads all German dictionary files, removes and suffix markers and outputs a de.dic file containing every word only once.

use egrep and regular expressions to find matching words. You might have a place where an "E" of  one word is followed by two empty cells and an "A" of another word:

egrep -hi 'e..a' de.dic
"." is the magic for a single char.

Running out of space in front of this combination? Search for everything having a maximum of one letter before it:

egrep -hi '^.?e..a' de.dic
The ^ char is matching "the beginning of a line" = the beginning of a word if each line holds one word and a questionmark "?" behind any char meany "maybe, maybe not" (exactly: the char left to the "?" must exist zero or one times), a "$" matches the end of a string. Click here fore more...

Fill up your holes and you'll build new ones until your grid is full enough. Now save it to a CSV file using a tabulator (tab) char as seperator. Run the following Perl line to convert the CSV file to HTML:

perl -nle 'chomp; @cols = split(/\t/); splice @cols,0,3; print "<tr>\n".join("\n",map { ++$c; s/^[a-z]$/<input type=text name="char$c" size=1 maxlength=1>/i; "\t<td>$_</td>"; } @cols)."\n</tr>\n";' <crossword.csv >crossword.html
The splice command cuts off 3 columns at the beginning (starting at column 0 = the first), adjust as needed or remove the whole command (including the ; ).

You'll get your fresh crossword puzzle as a HTML form (don't forget to add the <form> and <table> before and the closing tags at the end of the generated part).

All done, you got a fresh new unique HTML crossword puzzle!


1 Kommentar. Schreib was dazu

  1. When will we see this as a web application on your site?

Schreib was dazu

Die folgenden HTML-Tags sind erlaubt:<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>