Produce a program to correctly number a crossword grid.
Input
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 M
and N
. Following that line are M
lines each consisting of N
characters (plus a new line) selected
from [#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.
Output
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
triplet i
, m
, n
where i
represents a number to be printed
on the grid, and m
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.
Numbering scheme
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
Input:
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
Aside
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.
'\n'
in c on all platforms. The assumption is that the input file was produced on the same system that will process it, so this issue should be transparent. A general note about code-golf: if you're working in a strange language or on a strange platform simple make a note of anything that might surprise the reader. People will make allowance for that in judging your submission. \$\endgroup\$