/* Twenty puzzle in Picat. From Adrian Groza "Modelling Puzzles in First Order Logic" """ Puzzle 114. Twenty There are three ways to add four odd numbers and get 10: 1 + 1 + 3 + 5 = 10 1 + 1 + 1 + 7 = 10 1 + 3 + 3 + 3 = 10 Changes in the order of numbers do not count as new solutions. Now add eight odd numbers to get 20. To find all 11 solutions you will need to be systematic. (puzzle 49 from Kordemsky (1992)) """ Here are all 11 solutions: [1,1,1,1,1,1,1,13] [1,1,1,1,1,1,3,11] [1,1,1,1,1,1,5,9] [1,1,1,1,1,1,7,7] [1,1,1,1,1,3,3,9] [1,1,1,1,1,3,5,7] [1,1,1,1,1,5,5,5] [1,1,1,1,3,3,3,7] [1,1,1,1,3,3,5,5] [1,1,1,3,3,3,3,5] [1,1,3,3,3,3,3,3] 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 => Odds = [I*2 +1 : I in 0..10], N = 8, X = new_list(N), X :: Odds, sum(X) #= 20, % Symmetry breaking increasing(X), solve(X), println(x=X), fail, nl.