/* Circular constraint in Picat. Ensure that all the numbers 1..n in array x of length m are ordered and circular. Length of x mod m must be 0. 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 = 10, M = 5, X = new_list(N), X :: 1..M, circular(X,M), solve($[],X), println(X), fail, nl. go => true. circ(A,B,V) => B #= cond((1+A) mod V #= 0, V, (1+A) mod V). circular(X,V) => Len = X.len, if Len mod V != 0 then printf("circular: X.len mod V must be 0, is %w!\n", Len mod V) end, foreach(I in 2..Len) circ(X[I-1],X[I],V) end, circ(X[Len],X[1],V).