Albert Cardona<p><span class="h-card" translate="no"><a href="https://mathstodon.xyz/@joshg" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>joshg</span></a></span> Took a few minutes to type in, but it’s not egregious, the logic is straightforward and can be solved by hand easily. But it’s more instructive this way:</p><p>include "alldifferent.mzn";</p><p>% Two lists of ints between 1 and 5, both inclusive<br>% One we'll use for the indices of the matrix cell coordinates, and the other for cell values.<br>set of int: COORD = 1..5;<br>set of int: VALUE = 1..5;</p><p>% Define a matrix, which is a 2-dimensional array with indices for its cells<br>% defined by COORD, so between 1 and 5, where each matrix cell<br>% takes any value of those defined in the list VALUE:<br>array[COORD,COORD] of var VALUE: v;</p><p>% All different in rows: the 'j' coordinate advances in the column<br>constraint forall(i,j in v)(<br> alldifferent([v[i,j] | j in VALUE]));</p><p>% All different in columns: the 'i' coordinate advances in the row<br>constraint forall(i,j in v)(<br> alldifferent([v[i,j] | i in VALUE]));</p><p>% All the groups of cells that add up to 10,<br>% using either sums (+ sign) or multiplications (* sign)<br>constraint v[1,1] + v[1,2] + v[1,3] + v[1,4] = 10;<br>constraint v[1,5] + v[2,5] + v[3,5] = 10;<br>constraint v[2,1] + v[2,2] + v[3,1] = 10;<br>constraint v[2,3] * v[2,4] * v[3,4] = 10;<br>constraint v[3,2] + v[3,3] + v[4,2] = 10;<br>constraint v[4,1] + v[5,1] + v[5,2] = 10;<br>constraint v[4,3] + v[5,3] + v[5,4] + v[5,5] = 10;<br>constraint v[4,4] * v[4,5] = 10;</p><p>solve satisfy;</p><p><a href="https://mathstodon.xyz/tags/CSP" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>CSP</span></a> <a href="https://mathstodon.xyz/tags/minizinc" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>minizinc</span></a></p>