Skip to main content
deleted 4514 characters in body
Source Link

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.

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:

Valid and invalid 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:

InputOutputExplanation
.........TrueValid grid
#..............#TrueValid grid
...#........#...TrueValid grid
...#........#...TrueValid grid
.........TrueValid grid
#...#......#...#TrueValid grid
.........................TrueValid grid
##...#.............#...##TrueValid grid
.................................................TrueValid grid
........................#........................TrueValid grid
....###.....##......##.....##......##.....###....TrueValid grid
................................................................TrueValid grid
##....####....##...........##......##...........##....####....##TrueValid grid
...##.......#...........##.....##.....##...........#.......##...TrueValid grid
#...............FalseNo 180 degree symmetry
#..##..##..##..#False2-letter entries, filled-in columns
#........................FalseNo 180 degree symmetry
.......#...###...#.......False1-letter and 1-letter entries
######....#....#....#....FalseNo 180 degree symmetry, filled-in column & row
######...##...##...######FalseFilled-in columns & rows
...#......#......#......#......#......#......#...FalseWhite squares not contiguous, filled-in column
.................###....#....###.................False1-letter entries
...#......#...............##.....................FalseNo 180-degree symmetry
....#.......#.......#........######........#.......#.......#....FalseWhite squares not contiguous
..#.........#.......#......##......#.......#.......#.........#..False1-letter and 2-letter entries
.#......#..............................................#......#.False1-letter entries, white squares not contiguous
...........................##......#............................FalseNo 180-degree symmetry
####............................................................FalseNo 180-degree symmetry
#......##......##......##......##......##......##......##......#FalseFilled-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.

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:

Valid and invalid 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:

InputOutputExplanation
.........TrueValid grid
#..............#TrueValid grid
...#........#...TrueValid grid
...#........#...TrueValid grid
.........TrueValid grid
#...#......#...#TrueValid grid
.........................TrueValid grid
##...#.............#...##TrueValid grid
.................................................TrueValid grid
........................#........................TrueValid grid
....###.....##......##.....##......##.....###....TrueValid grid
................................................................TrueValid grid
##....####....##...........##......##...........##....####....##TrueValid grid
...##.......#...........##.....##.....##...........#.......##...TrueValid grid
#...............FalseNo 180 degree symmetry
#..##..##..##..#False2-letter entries, filled-in columns
#........................FalseNo 180 degree symmetry
.......#...###...#.......False1-letter and 1-letter entries
######....#....#....#....FalseNo 180 degree symmetry, filled-in column & row
######...##...##...######FalseFilled-in columns & rows
...#......#......#......#......#......#......#...FalseWhite squares not contiguous, filled-in column
.................###....#....###.................False1-letter entries
...#......#...............##.....................FalseNo 180-degree symmetry
....#.......#.......#........######........#.......#.......#....FalseWhite squares not contiguous
..#.........#.......#......##......#.......#.......#.........#..False1-letter and 2-letter entries
.#......#..............................................#......#.False1-letter entries, white squares not contiguous
...........................##......#............................FalseNo 180-degree symmetry
####............................................................FalseNo 180-degree symmetry
#......##......##......##......##......##......##......##......#FalseFilled-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.

added 27 characters in body
Source Link

enter image description hereValid and invalid crossword grids

Your challenge: given an integer \$n \geq 3\$a grid consisting of two unique values representing black and white squares, output alldetermine if it's a valid crossword grids (all \$n\$ bygrid. Assume that it's a square grid with \$n\$ grids of blackrows and columns (so there are \$n^2\$ white squares which follow the rules above/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):

Examples:

InputOutputExplanation
.........TrueValid grid
#..............#TrueValid grid
...#........#...TrueValid grid
...#........#...TrueValid grid
.........TrueValid grid
#...#......#...#TrueValid grid
.........................TrueValid grid
##...#.............#...##TrueValid grid
.................................................TrueValid grid
........................#........................TrueValid grid
....###.....##......##.....##......##.....###....TrueValid grid
................................................................TrueValid grid
##....####....##...........##......##...........##....####....##TrueValid grid
...##.......#...........##.....##.....##...........#.......##...TrueValid grid
#...............FalseNo 180 degree symmetry
#..##..##..##..#False2-letter entries, filled-in columns
#........................FalseNo 180 degree symmetry
.......#...###...#.......False1-letter and 1-letter entries
######....#....#....#....FalseNo 180 degree symmetry, filled-in column & row
######...##...##...######FalseFilled-in columns & rows
...#......#......#......#......#......#......#...FalseWhite squares not contiguous, filled-in column
.................###....#....###.................False1-letter entries
...#......#...............##.....................FalseNo 180-degree symmetry
....#.......#.......#........######........#.......#.......#....FalseWhite squares not contiguous
..#.........#.......#......##......#.......#.......#.........#..False1-letter and 2-letter entries
.#......#..............................................#......#.False1-letter entries, white squares not contiguous
...........................##......#............................FalseNo 180-degree symmetry
####............................................................FalseNo 180-degree symmetry
#......##......##......##......##......##......##......##......#FalseFilled-in columns

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.

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):

I also don't know if the final rule should be included, since it's not usually explicitly stated when constructing crosswords.

Valid and invalid 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):

Examples:

InputOutputExplanation
.........TrueValid grid
#..............#TrueValid grid
...#........#...TrueValid grid
...#........#...TrueValid grid
.........TrueValid grid
#...#......#...#TrueValid grid
.........................TrueValid grid
##...#.............#...##TrueValid grid
.................................................TrueValid grid
........................#........................TrueValid grid
....###.....##......##.....##......##.....###....TrueValid grid
................................................................TrueValid grid
##....####....##...........##......##...........##....####....##TrueValid grid
...##.......#...........##.....##.....##...........#.......##...TrueValid grid
#...............FalseNo 180 degree symmetry
#..##..##..##..#False2-letter entries, filled-in columns
#........................FalseNo 180 degree symmetry
.......#...###...#.......False1-letter and 1-letter entries
######....#....#....#....FalseNo 180 degree symmetry, filled-in column & row
######...##...##...######FalseFilled-in columns & rows
...#......#......#......#......#......#......#...FalseWhite squares not contiguous, filled-in column
.................###....#....###.................False1-letter entries
...#......#...............##.....................FalseNo 180-degree symmetry
....#.......#.......#........######........#.......#.......#....FalseWhite squares not contiguous
..#.........#.......#......##......#.......#.......#.........#..False1-letter and 2-letter entries
.#......#..............................................#......#.False1-letter entries, white squares not contiguous
...........................##......#............................FalseNo 180-degree symmetry
####............................................................FalseNo 180-degree symmetry
#......##......##......##......##......##......##......##......#FalseFilled-in columns

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.

added 27 characters in body
Source Link
Source Link
Loading