Skip to main content
2 of 4
added 27 characters in body

All Crossword Grids

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.

Example of a crossword grid

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:

enter image description here

Your challenge: given an integer \$n \geq 3\$, output all valid crossword grids (all \$n\$ by \$n\$ grids of black and white squares which follow the rules above). 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:

.....  #....  ##...  #....  ##...  ##...  
.....  .....  .....  #....  #....  ##...  
.....  .....  .....  .....  .....  .....  
.....  .....  .....  ....#  ....#  ...##  
.....  ....#  ...##  ....#  ...##  ...##  

....#  ...##  ....#  ...##  ...##  #...#  
.....  .....  ....#  ....#  ...##  .....  
.....  .....  .....  .....  .....  .....  
.....  .....  #....  #....  ##...  .....  
#....  ##...  #....  ##...  ##...  #...#  

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.