/* Circular chain - Enigma puzzle 985 in Picat. Problem from ECLiPSe example enigma985.pl """ Enigma 985 by Colin Singleton (New Scientist 27/6/98) George has invested his savings in gold - a circular chain of eight linked gold rings. The rings are all different sizes, although each is a whole number of ounces in weight - the total is 57 ounces. The chain has been designed so that the first time that George wishes to sell some of his gold, he can remove any whole number of ounces from the chain, either as a single link, or as a chain of linked rings. Given that there is no 3-ounce ring, nor a 6-ounce ring, list the weights of the eight rings in order, starting with the two smallest. """ 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 = 8, M = 57, Chain = new_list(N), Chain :: 1..M, ChainSum #= sum(Chain), ChainSum #= M, all_different(Chain), foreach(I in 1..N) Chain[I] #!= 3, Chain[I] #!= 6 end, Chain[1] #= 1, Chain[2] #< Chain[N], foreach(S in 1..M) member(I,1..N), member(J,1..N), sum([ ( (sum(Chain[I..J]) #= S) #\/ % or around the corner (sum(Chain[I..N]) + sum(Chain[1..J]) #= S )) ]) #>= 1 end, Vars = Chain, println(solve), solve($[ffd],Vars), println(chain=Chain), % println(chain2=Chain2), println(chainSum=ChainSum), % println(ijs=IJs), nl, % fail, nl. go => true.