/* Global constraint differ_from_at_least_k_pos in Picat. From Global Constraint Catalogue http://www.emn.fr/x-info/sdemasse/gccat/Cdiffer_from_at_least_k_pos.html """ Constraint differ_from_at_least_k_pos(K,VECTOR1,VECTOR2) ... Purpose Enforce two vectors VECTOR1 and VECTOR2 to differ from at least K positions. Example ( 2, <2, 5, 2, 0>, <3, 6, 2, 1> ) The differ_from_at_least_k_pos constraint holds since the first and second vectors differ from 3 positions, which is greater than or equal to K=2. """ 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, A1 = new_list(N), A1 :: 0..6, A2 = new_list(N), A2 :: 0..6, K :: 0..N, A1 = [2,5,2,0], % A2 = [3,6,2,1], K #= 2, differ_from_at_least_k_pos(K, A1, A2), Vars = A1 ++ A2 ++ [K], solve(Vars), println(a1=A1), println(a2=A2), println(k=K), nl, fail, nl. go => true. differ_from_at_least_k_pos(K, A1, A2) => sum([A1[I] #!= A2[I] : I in 1..A1.len]) #>= K.