Inspired by Flow Fit: Sudoku, a brand-new mobile puzzle game (as of Nov 2019).
Background
A Latin square is a square grid of side length \$ n \$ filled with \$ n \$ different symbols, where each row and column contains each symbol exactly once.
Let's define a row (resp. a column) as a maximally consecutive group of cells in horizontal (resp. vertical) direction. For example, the following board (O is a cell, - is a hole) has 8 rows and 8 columns in total:
The board | Rows | Columns O O O O O O | A A A A A A | A B C E G H O O O O O O | B B B B B B | A B C E G H O O - O O O | C C - D D D | A B - E G H O O O - O O | E E E - F F | A B D - G H O O O O O O | G G G G G G | A B D F G H O O O O O O | H H H H H H | A B D F G H Then, place the numbers \$ 1, \cdots, k \$ exactly once on each row and column, where \$ k \$ is the length of that row or column. For the board above, here is one solution:
3 4 1 2 5 6 4 3 2 1 6 5 1 2 - 3 1 2 2 1 3 - 2 1 5 6 1 2 3 4 6 5 2 1 4 3 A board is Latin-style if such a placement is possible.
Note that a row/column of size 1 is still a row/column, and therefore it can only have a single 1.
Challenge
Given a grid, determine if it is Latin-style, i.e. it is possible to place numbers on the grid so that each row/column of length \$ k \$ contains each of the numbers \$ 1, \cdots, k \$ exactly once.
Example Latin-style boards
O O O O O - O O O O - - O O O - - - O O - - - - O - O O O - O O O O O O O O O O O O O O O - O O O - - - O O O - O O O O O O O O O O O O O - O O O - - O O - - O O O O O O O O - O O O O - - O O O O - O O O O O O O O - - O O O O O - O O O O O O O O O O O O O O O O O O O O O O O O O O O - - O O O O O O O O O O O O O O O O O O O O O O O O O O O - O O O O O O - O O O - O O O - O O O - - O - - - O O O - O O - O O - O O O O O O O - O Example non-Latin-style boards
- O - O O O - O - O O O O O - - - O O - - - O O - - - O O O O O O O O O O O O O - - O O O - - O O O O O - - O O O - - O O O - - - O O - - - - O O O - - O O O O O O - O O O O O O O - O O O O O O - - O O O - - - - O O - - - O O - - - - O O - O O O O O - O O O O O - - - O O - - - O O O - - - - O O O - - O O O Input and output
You can take the grid input in any reasonable way. The grid's bounding box can be non-square, and the grid may contain multiple connected components.
You can give the output in one of two ways:
- Truthy/falsy values following the language's convention
- Swapping truthy/falsy is
not allowedalso allowed.
- Swapping truthy/falsy is
- One consistent value for true, another consistent value for false
Scoring and winning criterion
The standard code-golf rules apply. The shortest code in bytes wins.
False/Trueas long as they are consistent? \$\endgroup\$falseas consistent value fortrueand vice-versa given the second output-option). \$\endgroup\$