You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.9 KiB

5 months ago
  1. \item \lect Use propositional logic to solve Sudoku. Rules: A Sudoku grid consists of a 9x9 square, which is partitioned into nine 3x3 squares. The goal of the game is to write one number from 1 to 9 in each cell in such a way, that each row, each column, and each 3x3-square contains each number exactly once. Usually several numbers are already given.
  2. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  3. %%%% source: https://texample.net/tikz/examples/sudoku/
  4. %%%% Author: Roberto Bonvallet, published 2012-02-01, last accessed 2021-02-14, modified
  5. \newcounter{row}
  6. \newcounter{col}
  7. \newcommand\setrow[9]{
  8. \setcounter{col}{1}
  9. \foreach \n in {#1, #2, #3, #4, #5, #6, #7, #8, #9} {
  10. \edef\x{\value{col} - 0.5}
  11. \edef\y{9.5 - \value{row}}
  12. \node[anchor=center] at (\x, \y) {\n};
  13. \stepcounter{col}
  14. }
  15. \stepcounter{row}
  16. }
  17. \begin{center}
  18. \begin{tikzpicture}[scale=.35]
  19. \begin{scope}
  20. \draw (0, 0) grid (9, 9);
  21. \draw[very thick, scale=3] (0, 0) grid (3, 3);
  22. \setcounter{row}{1}
  23. \setrow { }{6}{ } {7}{ }{ } {1}{5}{ }
  24. \setrow { }{ }{3} {9}{ }{ } {8}{ }{ }
  25. \setrow { }{ }{2} {3}{ }{ } { }{4}{9}
  26. \setrow { }{ }{7} { }{ }{4} { }{ }{ }
  27. \setrow { }{4}{ } { }{9}{ } { }{8}{ }
  28. \setrow { }{ }{ } {1}{ }{ } {4}{ }{ }
  29. \setrow {6}{7}{ } { }{ }{9} {3}{ }{ }
  30. \setrow { }{ }{9} { }{ }{2} {5}{ }{ }
  31. \setrow { }{2}{8} { }{ }{7} { }{6}{ }
  32. \node[anchor=center] at (4.5, -1) {Sudoku};
  33. \end{scope}
  34. \end{tikzpicture}
  35. \end{center}
  36. In order to model SUDOKU using propositional logic, we first need to define the propositional variables that we
  37. want to use in our formula. We define variables $x_{ijk}$ for every row $i$,
  38. for every column $j$, and for every value $k$. This encoding yields to 729 variables ranging from $x_{111}$ to $x_{999}$.
  39. Using this variables, define the constraints for the rows, the columns, the 3x3-squares and the predefined numbers. \\
  40. \vspace{0.5cm}