/* Chain of Primes (Enigma #1216) in Picat. https://enigmaticcode.wordpress.com/2015/07/22/enigma-1216-chain-of-primes/ """ From New Scientist #2371, 7th December 2002 I have constructed a chain of ten 2-digit prime numbers. The ten primes that I have used are all different and except in the case of the first prime in the chain each prime’s first digit is the same as the previous prime’s second digit. In addition the fourth prime is the reverse of the first prime, and the tenth prime is the reverse of the seventh prime. What (in this order) are the third, sixth and ninth primes in this chain? """ 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 ?=> N = 10, % primes between 11..99 Primes = [P : P in primes(99), P >= 11], % 2 digit numbers X = new_list(N), X :: Primes, all_different(X), foreach(I in 2..N) X[I] div 10 #= X[I-1] mod 10 end, reversed(X[4],X[1]), reversed(X[7],X[10]), solve(X), println(x=X), println(solution=[X[3],X[6],X[9]]), fail, nl. go => true. % x is y reversed reversed(X,Y) => X mod 10 #= Y div 10, X div 10 #= Y mod 10 .