/* Enigma puzzle 1001 in Picat. From ECLiPSe example enigma1001.pl """ >From New Scientist, 17 October 1998, No 2156, p51 --------------------------------------------------- Enigma 1001: What the hex? - by Susan Denham --------------------------------------------------- IN THIS hexagon of circles I've written some digits: 1 8 7 0 1 9 4 9 2 7 2 5 Reading the six sides, clockwise, as three-figure numbers you get 187, 714, 425, 527, 799, and 901, all of which are multiples of 17. Your task today is to write a new collection of non-zero digits in the circles, with no two adjacent digits the same, so that the six three-figure numbers are all different multiples of some particular two-figure number, the number in the top row being twice that two-figure number. """ 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 ?=> X = new_list(12), X :: 1..9, Multipliers = new_list(6), Multipliers :: 1..99, Divisor :: 10..99, Numbers = new_list(6), Numbers :: 0..1001, foreach(I in 0..4) Numbers[I+1] #= 100*X[2*I+1] + 10*X[2*I+2]+X[2*I+3] end, Numbers[6] #= 100*X[11]+10*X[12]+X[1], % Multipler of number in top row is 2 Multipliers[1] #= 2, foreach(I in 1..6) Numbers[I] #= Multipliers[I]*Divisor end, all_different(Multipliers), foreach(I in 2..12) X[I] #!= X[I-1] end, X[12] #!= X[1], Vars = X ++ Multipliers ++ Numbers ++ [Divisor], solve(Vars), println(x=X), println(multipliers=Multipliers), println(numbers=Numbers), println(divisor=Divisor), nl, printf(" %d %d %d\n",X[1],X[2],X[3]), printf(" %d %d\n", X[12], X[4]), printf("%d %d\n", X[11], X[5]), printf(" %d %d\n", X[10], X[6]), printf(" %d %d %d\n",X[9], X[8],X[7]), fail, nl. go => true.