/* 3 coins problem in Picat. From http://www.cs.cf.ac.uk/htbin/Dave/AI/ai.pl?AI1/means_end.html+agenda+game+AI1/AI1.html+Lecture_12:_Agendas+Lecture_14:_Game_Playing+AI_TOP_LEVEL+LECTURE_13:_Means_End_Analysis """ Three coins lie on a table in the order tails, heads ,tails. In precisely three moves make them face either all heads or all tails, GPS generated 10 goals. """ 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 = 3, NumMoves = 3, X = new_array(N+1,N), X :: 0..1, % 0: heads, 1: tails Last :: [0,N], % last line, either all heads or all tails Init = [1,0,1], foreach(J in 1..N) X[1,J] #= Init[J] end, foreach(M in 2..NumMoves+1) sum([ X[M-1,J] #!= X[M,J] : J in 1..N]) #= 1 % one difference per move end, % either all heads or all tails Last #= sum([X[NumMoves+1,J] : J in 1..N]), solve(X), foreach(Row in X) println(Row) end, nl, fail, nl. go => true.