/* Divisible by 7 in Picat. (Attributed to Sam Loyd) """ Three numbers (6, 3 and 1) are drawn on the sides of three cubes - a number per cube. Can you arrange the three cubes in a line so that to create a 3-digit number divisible by 7? Each cube must be employed. """ 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 = 3, % The trick is - of course - that the 6 cube could be 9 as well X = new_list(N), X :: [1,3,6,9], Z #= 100*X[1] + 10*X[2] + X[3], all_different(X), Z mod 7 #= 0, % cannot have both a 6 and 9 count(6,X,#=,1) #<=> count(9,X,#=,0), Vars = X ++ [Z], solve(Vars), println(x=X), println(z=Z), nl, fail, nl. go => true.