/* Global constraint sum_free in Picat. From the Global Constraint Catalog http://www.emn.fr/x-info/sdemasse/gccat/Csum_free.html sum_free(S) """ Impose for all pairs of values (not necessarily distinct) i, j of the set S the fact that the sum i + j in not an element of S. """ Example: S = {1,3,5,9} Since 1+1 = 2 not in S 1+3 = 4 not in S 3+5 = 8 not in S ... """ Note: This implemented as an array, not a set. This program 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 = 20, X = new_list(N), X :: 1..M, sum_free(X), % Only sum_free/1: 6092 solutions product_free(X), % Including product_free/1: 2610 % Some additional constraints foreach(I in 1..100) at_most(3, X, I) end, sum(X) #= 100, increasing(X), solve(X), println(x=X), fail, nl. sum_free(X) => N = X.len, foreach(I in 1..N, J in 1..N, K in 1..N) X[K] #!= X[I] +X[J] end. product_free(X) => N = X.len, foreach(I in 1..N, J in 1..N, K in 1..N) X[K] #!= X[I] * X[J] end.