Takuzu is a logic game in which you have to complete a grid with cells containing
1s. The grid must follow 3 rules:
- No three horizontal or vertical consecutive cells can be the same.
- There must be an equal number of
1s in each row and column.
- No two rows can be the same, and no two columns can be the same.
Let's look at a finished grid:
0011 1100 0101 1010
As you can see, this board follows rule
3. There are no three horizontal or vertical cells that are the same, all the rows and columns contain an equal number of
1s, and no two rows and no two columns are the same.
Let's look at a grid that isn't valid:
110100 010011 011010 101100 100011 001101
There's a bunch of problems with this grid. For example, row
5 has three
0s in a row, and column
2 has three
1s in a row, followed by three
0s. Therefore, this is not a valid grid.
Your task is to make a program which, given a 2D array of
1s, verifies the board to see if it's a valid, finished Takuzu board.
0011 1100 0101 1010
This board follows all the rules, and is therefore a valid Takuzu board. You must return a truthy value for this.
This is not a valid board - row
1 doesn't follow rule
2. You must return a falsey value for this.
100110 101001 010101 100110 011010 011001
This is not a valid board, it fails (only) due to rule 3 - the first and fourth rows are the same.
110100 001011 010011 101100 100110 011001
This is not a valid board, it fails (only) due to rule 3 - the first and fourth columns are the same.
011010 010101 101100 010011 100110 101001
This is a valid board.
Rules and Specs:
- You can assume that all boards are square of dimensions
n * n, where
nis a positive even integer.
- You can assume that all boards are finished.
- You may take input as a 2D array containing values signifying
1, or as a string.
- You must output consistent truthy and falsey values for truthy and falsey boards, and the values representing "truthy" and "falsey" cannot be the same.
This is code-golf, so shortest code in bytes wins!