to be sudoku9

that's question to2 to1 not be2 the be1 or
be2 not or the be1 to2 that's question to1
be1 to1 the or question that's not be2 to2
to2 be1 that's question be2 to1 or the not
the be2 not that's to2 or be1 to1 question
to1 or question be1 the not be2 to2 that's
not to2 to1 be2 that's be1 question or the
question that's be2 to2 or the to1 not be1
or the be1 not to1 question to2 that's be2

MiniZinc model

include "globals.mzn"; 

int: n = 9;
int: m = 3;
array[1..n, 1..n] of int: puzzle;
array[1..n] of string: s = ["to<sub>1</sub>", 
                              "be<sub>1</sub>", 
                              "or", 
                              "not", 
                              "to<sub>2</sub>", 
                              "be<sub>2</sub>", 
                              "that's", 
                              "the", 
                              "question"];

array[1..n, 1..n] of var 1..n: x;

solve satisfy;

constraint
  forall(i, j in 1..n where puzzle[i,j] > 0) ( x[i,j] = puzzle[i,j])
;

constraint 
  forall(i in 1..n) ( alldifferent([x[i,j] | j in 1..n]) ) /\
  forall(j in 1..n) ( alldifferent([x[i,j] | i in 1..n]) ) /\
  forall(i in 0..m-1,j in 0..m-1) (
    alldifferent([x[r,c] | r in i*m+1..i*m+m, c in j*m+1..j*m+m])
  )
;


% Problem from JSR331, Sudoku.java
puzzle = array2d(1..9, 1..9, 
[  
  7,0,0,1,0,6,8,2,0,
  0,0,3,0,0,0,0,0,0,
  0,0,8,0,9,0,4,0,0,
  0,0,7,9,0,0,0,0,0,
  0,0,0,0,5,3,0,1,0,
  1,0,9,2,0,0,6,0,0,
  0,0,0,0,0,0,9,3,0,
  0,0,0,5,0,0,0,0,2,
  0,0,0,4,0,0,0,7,0
]);

output 
[
  if i = 1 /\ j = 1 then "<table>" else "" endif ++
  if j = 1 then "<tr>" else "" endif ++
  if j = 1 then "\n" else " " endif ++
    "<td>" ++ show(s[fix(x[i,j])]) ++ "</td>" ++
  if j = n then "</tr>" else "" endif ++
  if i = n /\ j = n then "</table>" else "" endif
  | i,j in 1..n
] ++ ["\n"];


Back to Constrained-based constraint poetry
Created by Hakan Kjellerstrand hakank@gmail.com