/*
Global constraint all_equal in Picat.
From Global Constraint Catalogue
http://www.emn.fr/x-info/sdemasse/gccat/Call_equal.html
"""
Constraint
all_equal(VARIABLES)
Purpose
Enforce all variables of the collection VARIABLES to take the same value.
Example
(<5, 5, 5, 5>)
The all_equal constraint holds since all its variables are fixed to value 5.
"""
Model created by Hakan Kjellerstrand, hakank@gmail.com
See also my Picat page: http://www.hakank.org/picat/
*/
import cp.
main => go.
go =>
N = 4,
Lower = 0,
Upper = 6,
List = findall(X, $all_equal_test(N,Lower, Upper,X)),
Len = length(List),
writeln(List),
writeln(length=Len),
nl.
all_equal_test(N, Lower, Upper, X) =>
X = new_list(N),
X :: Lower..Upper,
% x = [5,5,5,5],
all_equal(X),
solve([],X).
all_equal(X) =>
foreach(I in 2..X.length) X[I-1] #= X[I] end.