Takuzu Solver
Statement
Goal
Your program must output a solution to a Takuzu.A Takuzu, also known as Binairo, is a logic puzzle involving placement of two symbols (0 and 1) on a square grid.
The objective is to fill the grid with 1s and 0s, constraints are :
- an equal number of 1s and 0s in each row and column
- no more than two of either number adjacent to each other
- no identical rows and no identical columns
Similar to Sudoku, each puzzle begins with several squares in the grid already filled. Each test has only one possible solution.
Input
Line 1 : an integer n, dimension of the square grid.
n lines : a string line with n digits corresponding to that line. A "." is used for an empty space.
n lines : a string line with n digits corresponding to that line. A "." is used for an empty space.
Output
n lines : A string line with n digits corresponding to that line. The original numbers should not have changed, and there should be no "." left.
Constraints
0 < n <= 20
n is an even number
n is an even number
Example
Input
4 .1.0 ..0. .0.. 11.0
Output
0110 1001 0011 1100
Tags
Recursion, Logic
Difficulty
Hard
Test cases
Test 4x4 Test
Input
4
.1.0
..0.
.0..
11.0
Output
0110
1001
0011
1100
Validator 4x4 Validator
Input
4
0..0
..1.
.101
....
Output
0110
1010
0101
1001
Test 6x6 Test
Input
6
.....1
.0....
...0..
...00.
.0..0.
.0.0..
Output
010101
100110
011010
011001
100101
101010
Validator 6x6 Validator
Input
6
.1....
..0.1.
.....0
......
..00.0
..0..0
Output
011001
010011
101100
001101
110010
100110
Test 8x8 Test
Input
8
0..1....
.1..0..1
.....1.1
1..0....
..0..1..
..01...0
0..1.11.
10...0..
Output
01011010
01100101
10010101
10101010
01001101
11010010
00110110
10101001
Validator 8x8 Validator
Input
8
..00....
.....0..
........
..0..00.
........
.1..1.1.
..0..0.0
...0...0
Output
01001101
00110011
10100110
01011001
10110100
01001011
11010010
10101100
Test 10x10 Test
Input
10
00........
.....1....
...0.00..0
00.0......
......00..
.01..00...
...0.....0
.0...00..0
..........
.0.00.0..0
Output
0011011001
0101011001
1100100110
0010101101
1101010010
1010100101
0110011010
1001100110
0101101001
1010010110
Validator 10x10 Validator
Input
10
...1.1....
..0...0.0.
00..0.0...
0.......1.
...1......
....0.0..1
...0.1..0.
......0.0.
..0.......
....00...0
Output
0011011010
1100100101
0011010110
0100101011
1001101100
0110010011
1010011001
1101100100
0100110011
1011001100
Test 12x12 Test
Input
12
0....11..0..
...1...0....
.0....1...00
1..1..11...1
.........1..
0.0...1.....
....0.......
....01.0....
..00..0.0..0
.....1....1.
10.0........
..1....1..00
Output
010101101001
010101001011
101010110100
100100110011
011011001100
010010110011
101100101010
001101001101
110010010110
010101101010
101010010101
101011010100
Validator 12x12 Validator
Input
12
......1.1..0
....0.1...1.
..1.0....0.0
00......1...
....00...0..
..0.0...1...
......00.0.0
.00..1......
..0....1....
00.......0..
.......00...
00...0......
Output
011010101100
010100110011
101101010010
001011001101
110100110010
100100101101
011011001010
100101010101
110010110100
001011001011
110101100100
001010011011
Test 8x8 Hard Test
Input
8
...11..0
.0...0..
.00.....
1.......
.......1
..1.....
0.......
........
Output
01011010
00101011
10010101
11001010
01100101
10110010
01001101
10110100
Validator 8x8 Hard Validator
Input
8
.0..1.0.
.......1
....1...
...0....
.....11.
.0.1....
..11...0
.....0..
Output
10101001
01010101
01011010
10100101
01100110
10011001
00110110
11001010
Solution language
Solution
Stub generator input