All Crossword GridsIs it a Valid Crossword Grid?
In crossword terminology, the grid is the region into which the crossword answers are inserted, consisting of white and black squares. The crossword answers, called entries, are inserted into contiguous sequences of white squares in a row or column, separated by black squares.
For straight (American) crosswords, the grids usually follow a specific set of rules:
- They should have 180 degree rotational symmetry (if there is a black square in the \$x\$th row and \$y\$th column, there should be a black square in the \$x\$th-to-last row and \$y\$th-to-last column).
- All entries must be at least 3 squares long.
- All white squares must be joined in a single region.
- No row/column can be completely filled with black squares.
Some examples of invalid and valid crossword grids:
Your challenge: given a grid consisting of two unique values representing black and white squares, determine if it's a valid crossword grid. Assume that it's a square grid with \$n\$ rows and columns (so there are \$n^2\$ white/black cells), where \$n \geq 3\$. For example, if \$n=3\$ there is only one valid grid (I'm using .
for white cells and #
for black cells):
...
...
...
If \$n=4\$, there are 3 valid grids:
.... #... ...#
.... .... ....
.... .... ....
.... ...# #...
If \$n=5\$, there are 12 valid grids:
..... #.... ##... #.... ##... ##...
..... ..... ..... #.... #.... ##...
..... ..... ..... ..... ..... .....
..... ..... ..... ....# ....# ...##
..... ....# ...## ....# ...## ...##
....# ...## ....# ...## ...## #...#
..... ..... ....# ....# ...## .....
..... ..... ..... ..... ..... .....
..... ..... #.... #.... ##... .....
#.... ##... #.... ##... ##... #...#
Examples:
Input | Output | Explanation |
---|---|---|
......... |
True | Valid grid |
#..............# |
True | Valid grid |
...#........#... |
True | Valid grid |
...#........#... |
True | Valid grid |
......... |
True | Valid grid |
#...#......#...# |
True | Valid grid |
......................... |
True | Valid grid |
##...#.............#...## |
True | Valid grid |
................................................. |
True | Valid grid |
........................#........................ |
True | Valid grid |
....###.....##......##.....##......##.....###.... |
True | Valid grid |
................................................................ |
True | Valid grid |
##....####....##...........##......##...........##....####....## |
True | Valid grid |
...##.......#...........##.....##.....##...........#.......##... |
True | Valid grid |
#............... |
False | No 180 degree symmetry |
#..##..##..##..# |
False | 2-letter entries, filled-in columns |
#........................ |
False | No 180 degree symmetry |
.......#...###...#....... |
False | 1-letter and 1-letter entries |
######....#....#....#.... |
False | No 180 degree symmetry, filled-in column & row |
######...##...##...###### |
False | Filled-in columns & rows |
...#......#......#......#......#......#......#... |
False | White squares not contiguous, filled-in column |
.................###....#....###................. |
False | 1-letter entries |
...#......#...............##..................... |
False | No 180-degree symmetry |
....#.......#.......#........######........#.......#.......#.... |
False | White squares not contiguous |
..#.........#.......#......##......#.......#.......#.........#.. |
False | 1-letter and 2-letter entries |
.#......#..............................................#......#. |
False | 1-letter entries, white squares not contiguous |
...........................##......#............................ |
False | No 180-degree symmetry |
####............................................................ |
False | No 180-degree symmetry |
#......##......##......##......##......##......##......##......# |
False | Filled-in columns |
Standard loopholes are forbidden. Shortest code wins.
Sandbox Questions
I may have misused some crossword terminology above, let me know if I can improve the explanation.
I also don't know if the final rule should be included, since it's not usually explicitly stated when constructing crosswords.
I'm considering adding an optional parameter \$n\$ which describes the number of rows/columns to make the input easier to parse, but I don't know how people feel about optional parameters.