1

I am trying to interpret a clingo code for a sudoku and the last two lines confuse a lot. Is there anyone experienced with that, who can explain to me what I see?

%same_line(X1,X2) :- value(X1), value(X2), (X1-1)/3 == (X2-1)/3.
%:- sudoku(X1,Y1,N), sudoku(X2,Y2,N), same_line(X1,X2), same_line(Y1,Y2), X1 != X2, Y1 != Y2.

What I think I understand is that in the first line it is described how the values are being distributed in every line and in the second line I believe it is a constrain rule that would delete a row, column or subgrid with the same number. The X1 != X2 and Y1 != Y2 is also abit confusing

logi-kal
  • 7,107
  • 6
  • 31
  • 43
Myrto.S
  • 11
  • 1

1 Answers1

0

This seems to be the rule that each square of 3x3 can contain each number only once.

Second rule reads something like

It can not be, that for two different fields (X1,Y1) and (X2,Y2)
which both have value N, 
that  X1 and X2 are on the same line and Y1 and Y2 are on the same line.

Another way to write it would be

:- sudoku(X1,Y1,N1), same_line(X1,X2), X1<X2, same_line(Y1,Y2), Y1<Y2, 
   sudoku(X2,Y2,N2), N1=N2.

DuDa
  • 3,718
  • 4
  • 16
  • 36