this repo has no description
1include "alldifferent.mzn";
2
3int: n;
4
5array[1..n] of var 1..n: y; % position of each number
6array[1..n-1] of var 1..n-1: v; % position of difference i
7
8constraint alldifferent(y);
9constraint alldifferent(v);
10constraint forall(i,j in 1..n where i < j)(
11 (y[i] - y[j] = 1 -> v[j-i] = y[j]) /\
12 (y[j] - y[i] = 1 -> v[j-i] = y[i])
13 );
14
15constraint abs(y[1] - y[n]) = 1 /\ v[n-1] = min(y[1], y[n]);
16
17solve :: int_search(y, first_fail, indomain_min)
18 satisfy;
19
20array[1..n] of 1..n: x :: output_only
21 = [ sum(i in 1..n)(i*(fix(y[j]) = i)) | j in 1..n ];
22output [ "x = \(x);\n" ]