Produce a program to correctly number a crossword grid.
The input will be the name of a file representing the crossword grid. The input filename may be passed as an argument, on the standard input, or by other conventional means other than hardcoding.
Grid file format: A text file. The first line consists of two white-space
separated integer constants
N. Following that line are
lines each consisting of
N characters (plus a new line) selected
[#A-Z ]. These characters are interpreted such that
indicates a blocked square,
' ' a open square in the puzzle
with no known contents and any letter an open square whose
containing that letter.
The output will be a numbering file, and may be sent to the standard output, to a file whose name is derived from the input filename, to a user specified file, or to some other conventional destination.
Numbering file format A text file. Lines starting with '#' are ignored and
may be used for comments. All other lines contain a tab separated
i represents a number to be printed
on the grid, and
n represent the row and column of the
square where it should be printed. The number of both rows and
columns starts at 1.
A correctly numbered grid has the following properties:
- Numbering begins at 1.
- No column or span of open squares is unnumbered. (You may assume that no single character answer will exist in the problem.)
- Numbers will be encountered in counting order by scanning from top row to the bottom taking each row from left to right. (So, every horizontal span is numbered at its leftmost square, and every column is numbered at its topmost square.)
Test input and expected output
5 5 # ## # # # ## #
Output (neglecting comment lines):
1 1 2 2 1 3 3 2 2 4 2 4 5 2 5 6 3 1 7 3 4 8 4 1 9 4 3 10 5 3
This is the first of what will hopefully be several crossword related challenges. I plan to use a consistent set of file-formats throughout and to build up a respectable suite of crossword related utilities in the process. For instance a subsequent puzzle will call for printing a ASCII version of the crossword based on the input and output of this puzzle.