ILP Part 84 — Na koń

This is the eightieth fourth part of the ILP series. For your convenience you can find other parts in the table of contents in Part 1 – Boolean algebra

Today we are going to solve Na koń. Code:

First, we create variables in line 3. We define one binary digit for each field of the board indicating whether the night is there or not.

Next, we define all possible moves in lines 5-14.

Finally, we iterate over all fields and use if condition to enforce that there must be one neighbour if given field is selected. So we sum all neighbours (line 24), we use material implication to indicate that if the current field is selected (line 21) then the sum of neighbours must be equal to (22-25).

Output: