/* Global constraint all_same_except_0 in Picat. all_same_except_0(X) ensures that all values > 0 in the list X are the same. Note that it is not necessary that there are any 0s in the list. For a "real world" example of this constraint, see http://hakank.org/picat/coins_41_58.pi 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 = 5, X = new_list(N), X :: 0..N, all_same_except_0(X), solve(X), println(X), fail, nl. go => true. all_same_except_0(X) => N = X.len, foreach(I in 1..N, J in 1..N) X[I] #= X[J] #\/ X[I] #= 0 #\/ X[J] #= 0 end.