ILP Part 65 – Fancy sudoku

This is the sixtieth fifth 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’re going to solve a modification of classical Sudoku riddle shown in Precz z cyframi.

We need to fill the board with digits as in Sudoku and meet some additional constraints:

  • Field with X indicates that number in that field is equal to the number of different values in corner neighbours of the field (so top-left field, top-right, bottom-left and bottom-right)
  • Field with + indicates that among four straight neighbours (field above, below, to the left, to the right) there are two which added values are equal to the value in the field
  • Field with circle indicates that field is equal to the number of different values in all neighbours

Additionally, the board is filled with all crosses, pluses and circles completely. This means that if given field is empty then no cross/field/circle can be placed in it.

Solution:

Lines 25-52 are regular Sudoku rules.

Next, in lines 54-106 we encode additional rules. First, we extract corner neighbours (lines 57-63), straight neighbours (65-71), and all neighbours together (line 73). Next, we prepare sums of pairs of straight neighbours (line 75) and then compare them with current field value.

Finally, in lines 78-103 we encode the rules. If field is of type 0 then it means field is empty so number of different values for corner neighbours must not be equal to the current value, number of straight neighbours summing to the current field value is zero (so no sum matches), and similarly for all neighbours – number of different values among them does not match current value.

Type 1 indicates X, type 2 is +, type 3 is circle, type 4 is + with circle. Notice that X with circle is not possible, nor is X with + with circle.

Output: