I've encountered a problem that seems very simple, but turned out to just be frustrating, and now I seek math experts to help me. I've got a square table with Light Blue, White, Red and Green blocks.
The Light Blue blocks cuts the table in two equal parts diagonally from the top left to bottom right. The bottom left half of the table is a mirror image of the top right, but the Red/Green boxes are inverted / opposites.
Rules of the puzzle:
- Only whole numbers allowed and you can only put numbers in red and green blocks.
- Red blocks must contain negative numbers
- Green blocks must contain positive numbers
- All the white blocks and light blue blocks count as 0 and this is not allowed to change
- Boxes that are mirror opposites must add up to 0
Aim of the puzzle:
In the end all the columns must add up to 0 and all the rows must add up to to 0
I would appreciate solutions to this puzzle, but what I really would like is if some math expert out there could give me the smallest whole number solution.
What I mean is: If I have two solutions, and I add up the numbers in all the green blocks for both of them, then the solution with the lower sum would be "smaller".
Even better would be if someone could explain to me how to find the smallest whole number solution for other tables, with different red/green configurations or different sizes, that work in the same way.
I would like to find a general optimal solution, if such a solution actually exists in reality.
Here's an attempted solution:
Here are solutions I've found so far:
Solution 1:

Solution 2:

Any help would be appreciated.



This can be formulated as an Integer Programming or Constraint Programming problem. Let $x_{ij} \in \mathbb{Z}$ be the value of cell $(i,j)$, then
$$\begin{align} &x_{i,j} = 0 && \text{white and blue cells}\\ &x_{i,j} \ge 1 && \text{green cells}\\ &x_{i,j} \le -1 && \text{red cells}\\ &x_{i,j}= -x_{j,i} && \forall i<j\\ &\sum_i x_{i,j} = 0 &&\forall j\\ &\sum_j x_{i,j} = 0 &&\forall i\\ \end{align}$$
These are all linear constraints. (The model can be reformulated by skipping all white/blue cells: that would make the problem smaller).
I tried your problem, and if I made no errors transcribing the data, the problem does not have a feasible solution. (Well, I made some errors. See below for updated results).
Update
After fixing my input data, and adding the objective: $$\min \sum_{(i,j) \in Green} x_{i,j}$$ I get:
The total value of the green cells is 87 (this is the optimal value: no better solution exists). This solution was found in 0.28 seconds.