att vara n-queens2d

MiniZinc model

include "globals.mzn";
int: n;
array[1..n] of var 1..n: x;
array[1..n] of string: s; 
solve satisfy;
constraint all_different(x);
constraint all_different([x[i]+i | i in 1..n]);
constraint all_different([x[i]-i | i in 1..n]);

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

n = 8;
s = ["att    ",
     "vara   ",
     "eller  ",
     "inte   ",
     "vara   ",
     "det    ",
     "är     ",
     "frågan "];

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