/* Constraints contains and not_contains in Picat. contains_array(E,X): is E in list X? not_contains_array(E,X): is E not in list X? Both these constraints are reversible. 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 = 9, X = new_list(N), X :: 0..N, E :: 0..N, Num #> 0, % E #= 7, % X = [0,1,1,3,4,5,6,7,7], contains(E, X), to_num(X, 10, Num), Num #= 123402345, Vars = X ++ [E,Num], solve(Vars), println(x=X), println(e=E), println(num=Num), nl, fail, nl. go => true. % % Test not_contains/2 % go2 ?=> N = 9, X = new_list(N), X :: 0..N, E :: 0..N, Num #> 0, % E #= 7, % X = [0,1,1,3,4,5,6,7,7], not_contains(E, X), % contains(E, X), to_num(X, 10, Num), Num #= 123402345, Vars = X ++ [E,Num], solve(Vars), println(x=X), println(e=E), println(num=Num), nl, fail, nl. go2 => true. % % Does list/array A contains the element E % contains(E, A) => sum([A[I] #= E : I in 1..A.len]) #>= 1. % % Does list/array A contains the element E % not_contains(E, A) => sum([A[I] #= E : I in 1..A.len]) #= 0. % % converts a number Num to/from a list of integer List given a base Base % to_num(List, Base, Num) => Len = length(List), Num #= sum([List[I]*Base**(Len-I) : I in 1..Len]).