/* Magic five-pointed star in Picat. From Adrian Groza "Modelling Puzzles in First Order Logic" """ Puzzle 90. Magic five-pointed star It is required to place a different number in every circle so that the four circles in a line shall add up to 24 in all the five directions. First, show that no solution is possible with values from 1 to 10. Second, can you show that no solution exists for any 10 consecu- tive numbers? Third, find a solution assuming that you can use any whole numbers you like. How many solutions can you find with values up to 12? (adapted from puzzle 395 from Dudeney 2016) """ a1 a2 b2 b1 a5 b3 b5 b4 a3 a4 Here is one solution: [1,2,3,4,5, 9,8,12,6,10] 1 2 8 9 5 12 10 6 3 4 This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. /* First part: There is no solution for 1..10 */ go => p(1,10,X), println(X), nl, fail, nl. /* There is no solutions for N..N+10 */ go2 => member(N,1..20), println(n=N), p(N,N+10,X), println(x=X), fail, nl. /* All 240 solutions for N=1..13 [1,2,3,4,5,9,8,12,6,10] [1,2,3,4,6,9,7,13,5,10] [1,2,3,9,5,4,13,7,6,10] [1,2,3,9,6,4,12,8,5,10] [1,2,10,7,5,13,4,9,6,3] ... */ go3 => member(N,10..13), println(n=N), p(1,N,X), println(X), fail, nl. /* Number solutions for 1..N, N=10..13 10 = 0 11 = 0 12 = 120 13 = 240 There are 120 solutions with max 12 and 120 solutions with max 13. There is no solution with both 12 and 13. */ go4 => member(N,10..13), C = count_all(p(1,N,_X)), println(N=C), fail, nl. p(Start,Max, X) => X = new_list(10), X :: Start..Max, [A1,A2,A3,A4,A5,B1,B2,B3,B4,B5] = X, all_different(X), A1 + B2 + B3 + A3 #= 24, A2 + B2 + B1 + A5 #= 24, A3 + B4 + B5 + A5 #= 24, A1 + B1 + B5 + A4 #= 24, A2 + B3 + B4 + A4 #= 24, solve(X).