/* Global constraint k-alldifferent in Picat. http://www.emn.fr/x-info/sdemasse/gccat/Ck_alldifferent.html """ For each collection of variables depicted by an item of VARS, enforce their corresponding variables to take distinct values. Example ( < vars-<5, 6, 0, 9, 3>, vars-<5, 6, 1, 2> > ) The k_alldifferent constraint holds since all the values 5, 6, 0, 9 and 3 are distinct and since all the values 5, 6, 1 and 2 are distinct as well. """ This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go ?=> N = 2, M = 5, X = new_array(N,M), X :: 0..9, X = {{5,6,0,9,3}, {5,6,1,2,_}}, k_all_different(X), solve(X), foreach(Row in X) println(Row) end, nl, fail, nl. go => true. % % k_all_different % (all rows satisfy the all_different constraint) % k_all_different(X) => N = X.len, M = X[1].len, foreach(I in 1..N) all_different([X[I,J] : J in 1..M]) end.