/* Combination Locks problem (PuzzlOR) in Picat. From http://puzzlor.editme.com/combinationlocks """ Many people store their valuables in home safes because they protect against burglaries and fires. They are a good place for storing insurance documents, car titles, cash, and many other valuables. Figure 1 shows six dials that are on the front of your home safe. In order to open the safe, you must set each of the dials to one number. When the correct numbers are selected on each dial, the safe will open. Unfortunately you have forgotten the combination. All you can remember is that the numbers on all of the dials summed to 419. Question: What numbers should you select in order to unlock the safe? """ 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 = 6, Dials = [ [39,57,15,88,75,06], [09,64,48,68,58,02], [29,91,08,67,16,55], [40,25,32,22,66,54], [49,30,14,41,17, 1], [44, 3,46,83,10,63]], % decision variables X = new_list(N), X :: 0..max(Dials.flatten), foreach(I in 1..N) sum([X[I] #= Dials[I,J] : J in 1..N]) #= 1 end, sum(X.vars) #= 419, solve(X), println(x=X), fail, nl. go => true.