/* Yet another weighing in Picat. From https://en.wikibooks.org/wiki/Puzzles/Decision_puzzles/Yet_Another_Weighing """ You have a balance and the following items of which you know the weights: a stapler weighing 80g, a pen weighing 40g, an eraser weighing 20g, a ruler weighing 10g, and a small coin weighing 5g. How many different weights can you measure with these items? """ One can get meaure 31 different weights. The model generates 212 solutions: [[5,-1,-1,-1,-1,1],[5,-1,-1,-1,1,0],[5,-1,-1,1,0,0],[5,-1,1,0,0,0],[5,1,0,0,0,0],[10,0,-1,-1,-1,1],[10,0,-1,-1,1,0],[10,0,-1,1,0,0],[10,0,1,0,0,0],[15,-1,0,-1,-1,1],[15,-1,0,-1,1,0],[15,-1,0,1,0,0],[15,1,-1,-1,-1,1],[15,1,-1,-1,1,0],[15,1,-1,1,0,0],[15,1,1,0,0,0],[20,0,0,-1,-1,1],[20,0,0,-1,1,0],[20,0,0,1,0,0],[25,-1,-1,0,-1,1],[25,-1,-1,0,1,0],[25,-1,1,-1,-1,1],[25,-1,1,-1,1,0],[25,-1,1,1,0,0],[25,1,0,-1,-1,1],[25,1,0,-1,1,0],[25,1,0,1,0,0],[30,0,-1,0,-1,1],[30,0,-1,0,1,0],[30,0,1,-1,-1,1],[30,0,1,-1,1,0],[30,0,1,1,0,0],[35,-1,0,0,-1,1],[35,-1,0,0,1,0],[35,1,-1,0,-1,1],[35,1,-1,0,1,0],[35,1,1,-1,-1,1],[35,1,1,-1,1,0],[35,1,1,1,0,0],[40,0,0,0,-1,1],[40,0,0,0,1,0],[45,-1,-1,-1,0,1],[45,-1,-1,1,-1,1],[45,-1,-1,1,1,0],[45,-1,1,0,-1,1],[45,-1,1,0,1,0],[45,1,0,0,-1,1],[45,1,0,0,1,0],[50,0,-1,-1,0,1],[50,0,-1,1,-1,1],[50,0,-1,1,1,0],[50,0,1,0,-1,1],[50,0,1,0,1,0],[55,-1,0,-1,0,1],[55,-1,0,1,-1,1],[55,-1,0,1,1,0],[55,1,-1,-1,0,1],[55,1,-1,1,-1,1],[55,1,-1,1,1,0],[55,1,1,0,-1,1],[55,1,1,0,1,0],[60,0,0,-1,0,1],[60,0,0,1,-1,1],[60,0,0,1,1,0],[65,-1,-1,0,0,1],[65,-1,1,-1,0,1],[65,-1,1,1,-1,1],[65,-1,1,1,1,0],[65,1,0,-1,0,1],[65,1,0,1,-1,1],[65,1,0,1,1,0],[70,0,-1,0,0,1],[70,0,1,-1,0,1],[70,0,1,1,-1,1],[70,0,1,1,1,0],[75,-1,0,0,0,1],[75,1,-1,0,0,1],[75,1,1,-1,0,1],[75,1,1,1,-1,1],[75,1,1,1,1,0],[80,0,0,0,0,1],[85,-1,-1,-1,1,1],[85,-1,-1,1,0,1],[85,-1,1,0,0,1],[85,1,0,0,0,1],[90,0,-1,-1,1,1],[90,0,-1,1,0,1],[90,0,1,0,0,1],[95,-1,0,-1,1,1],[95,-1,0,1,0,1],[95,1,-1,-1,1,1],[95,1,-1,1,0,1],[95,1,1,0,0,1],[100,0,0,-1,1,1],[100,0,0,1,0,1],[105,-1,-1,0,1,1],[105,-1,1,-1,1,1],[105,-1,1,1,0,1],[105,1,0,-1,1,1],[105,1,0,1,0,1],[110,0,-1,0,1,1],[110,0,1,-1,1,1],[110,0,1,1,0,1],[115,-1,0,0,1,1],[115,1,-1,0,1,1],[115,1,1,-1,1,1],[115,1,1,1,0,1],[120,0,0,0,1,1],[125,-1,-1,1,1,1],[125,-1,1,0,1,1],[125,1,0,0,1,1],[130,0,-1,1,1,1],[130,0,1,0,1,1],[135,-1,0,1,1,1],[135,1,-1,1,1,1],[135,1,1,0,1,1],[140,0,0,1,1,1],[145,-1,1,1,1,1],[145,1,0,1,1,1],[150,0,1,1,1,1],[155,1,1,1,1,1]] But just 31 of them are unique measures: [5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100,105,110,115,120,125,130,135,140,145,150,155] 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 ?=> Ws = [5,10,20,40,80], Len = Ws.len, X = new_list(Len), X :: -1..1, W #= sum([X[I]*Ws[I] : I in 1..Len]), W #>= 1, % We can only weigh positive weights Vars = [W] ++ X, All=solve_all(Vars), println(All.sort), println(num_results=All.len), Unique = [A[1] : A in All].sort_remove_dups, println(unique=Unique), println(num_unique=Unique.len), nl. go => true.