/* Subset sum problem in Picat. From Katta G. Murty: "Optimization Models for Decision Making", page 340 http://ioe.engin.umich.edu/people/fac/books/murty/opti_model/junior-7.pdf """ Example 7.8.1 A bank van had several bags of coins, each containing either 16, 17, 23, 24, 39, or 40 coins. While the van was parked on the street, thieves stole some bags. A total of 100 coins were lost. It is required to find how many bags were stolen. """ Model created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go => N = 6, Total = 100, Coins = [16, 17, 23, 24, 39, 40], Len = length(Coins), X = new_list(Len), X :: 0..N, scalar_product(Coins, X, Total), NumStolen #= sum(X), % total number of bags stolen solve(X), writeln(coins=Coins), writeln(total=Total), writeln(x=X), writeln(num_stolen=NumStolen). scalar_product(A, X, Product) => Product #= sum([S : I in 1..A.length, S #= A[I]*X[I]]).