/* Global constraint consecutive_values in Picat. From Global Constraint Catalog: http://www.emn.fr/z-info/sdemasse/gccat/Cconsecutive_values.html """ Purpose: Constraint the difference between the largest and the smallest values of the VARIABLES collection to be equal to the number of distinct values assigned to the variables of the VARIABLES collection minus one (i.e., there is no holes at all within the used values). Example: (5,4,3,5) """ 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 = 4, X = new_list(N), X :: 1..9, % X = [5,4,3,5], % should be accepted % X = [1,4,3,5], % should fail consecutive_values(X), solve(X), println(X), fail, nl. go => true. consecutive_values(X) => NV :: 1..X.len, nvalue(NV, X), max(X) - min(X) #= NV - 1.