I'm going crazy with this problem that I have to solve with Numberjack, that is a library in python for CSP. We have n x m squares with colored sides. These squares must be arranged in a n x m grid in such a way that the squares' adjacent sides are of the same color. The square can be rotated and shifted. An example:
I thought about using 4 matrix (one for nord, one for sud, one for west and one for east side ) and a number for a color. Nord(i,j), West(i,j), East(i,j), Sud(i,j) describe the square i,j on the grid. Which constraints i have to consider?