/* Value circle puzzle in Picat. From Chris Smith's Math Newsletter #548 """ Numbers are to be written in every section of this diagram, representing the sum of all the numbers in any neighbouring section (so for example, value of '*' would be obtained by adding the numbers in each pink section. [image (it should be nice circles :-)) |---------------------- | | b | | ------------ | | a |\ d /| | | -4 | \------/ | | | | | *g |e | | | / | ------ |\ | | / | g | 2 | \ | | / |---------- \ | |/ c \| ------------------------ ] What is the value if '*' [g]? """ This model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go ?=> L = [A,B,C,D,E,F,G], L :: -10..10, A #= -4, E #= 2, Neighbours = [ [A,[B,D,C,F]], % A [B,[A,C,D,E]], % B [C,[A,B,F,E]], % C [D,[A,B,F,E,G]], % D [E,[B,C,D,F,G]], % E [F,[A,C,D,E,G]], % F [G,[D,E,F]] % G ], foreach(N in Neighbours) N[1] #= sum(N[2]) end, solve(L), println([a=A,b=B,c=C,d=D,e=E,f=F,g=G]), fail, nl. go => true.