to be magic square
- not or the question to to be that's be
- be to the that's to or be question not
- be that's be question to to not or the
- the to be or to that's not question be
- be question not that's to or be to the
- the or not to to question be that's be
- not question be or to that's the to be
- be that's be to to question the or not
MiniZinc model
include "globals.mzn";
int: n = 3;
int: total = ( n * (n*n + 1)) div 2;
array[1..n*n] of string: s =
["to", "be", "or", "not", "to", "be", "that's", "the", "question"];
array[1..n,1..n] of var 1..n*n: magic;
solve satisfy;
constraint
all_different([magic[i,j] | i in 1..n, j in 1..n]) /\
forall(k in 1..n) (
sum(i in 1..n) (magic[k,i]) = total /\
sum(i in 1..n) (magic[i,k]) = total
)
/\
sum(i in 1..n) (magic[i,i]) = total
/\
sum(i in 1..n) (magic[i,n-i+1]) = total
;
output
[
if i = 1 /\ j = 1 then "<li>" else "" endif ++
show(s[fix(magic[i,j])]) ++ " "
| i,j in 1..n
];
Back to Constrained-based constraint poetry
Created by Hakan Kjellerstrand hakank@gmail.com