Binox is a logic puzzle described as follows: given a grid of squares with some cells already filled with X or O.
Player needs to complete the grid by filling in the empty cells with X or O, satisfying the following conditions:
The grid is completely covered by X and O
In each row/column, there is no sequence of more than 2 consecutive cells filled with the same symbol
In each row/column, the number of X is equal to the number of O
Each row/column is unique (No two rows are the same, and no two columns are the same)
Below is an example of a 6×6 Binox puzzle and its solution.
In each row, the number of X is equal to the number of O
j=0∑nC−1x(i,j)=2nC,∀0≤i<nR
In each column, the number of X is equal to the number of O
i=0∑nR−1x(i,j)=2nR,∀0≤j<nC
Each row is unique. To linearize this constraint, we can rephrase it as follows:
for any two rows i and j, there exists at least one position k such that x(i,k)=x(j,k).
For any two distinct rows i=j, and for each column k, we define an intermediate variable y(i, j, k) such that
y(i,j,k)={10if x(i,k)=x(j,k)otherwise
Using geometric method
we can represent the variables y through the variables x by the following constraints:
We linearize the original constraint using the variables y as follows
k=0∑nC−1y(i,j,k)≤nC−1,∀0≤i,j<nR,i=j
Each column is unique. Similarly to the above condition, for any two distinct columns i and j,
and for each row k, we construct an intermediate variable z(i,j,k) such that
z(i,j,k)={10if x(k,i)=x(k,j)otherwise
Represent the variables z through the variables x by the following constraints:
This problem does not have an objective function, as we are not aiming to minimize
or maximize any value. Our goal is simply to find a feasible solution. Technically,
when programming, we can set the objective function to a constant (I often choose 0)
The highlight of this puzzle is the unique row/column constraint. In reality,
such constraints are often very difficult to model efficiently. Imagine if we
had thousands of rows or columns; the number of constraints would be enormous.
In such cases, we must find alternative ways to solve the problem effectively
For more Binox puzzles and variations, please refer to Krazydad.
The Python code for Binox modeling is available at
Tung-hehe