/* Coins planning in Picat. From Thinking as Computation: Three coins problem """ The three-coins problem formulated for the general planner. The three possible moves. Each changes one of the coins. """ This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import planner. main => go. go ?=> initial_state(Init), % L=new_list(3), % exactly three steps time(plan(Init,3,L)), write(L), nl, writeln(len=L.length), fail, nl. go => true. initial_state(Initial) => Initial = [h,h,t]. final(Goal) ?=> Goal = [h,h,h]. final(Goal) => Goal = [t,t,t]. % The three-coins problem formulated for the general planner. % The three possible moves. Each changes one of the coins. action(From, To, Move, Cost) ?=> From=[X,Y,Z],Move=flip_left,To=[X1,Y,Z], Cost = 1, opposite(X,X1). action(From, To, Move, Cost) ?=> From=[X,Y,Z],Move=flip_middle,To=[X,Y1,Z], Cost = 1, opposite(Y,Y1). action(From, To, Move, Cost) => From=[X,Y,Z],Move=flip_right,To=[X,Y,Z1], Cost = 1, opposite(Z,Z1). opposite(H,T) ?=> H=h,T=t. % Flipping a head gives a tail. opposite(T,H) => T=t,H=h. % Flipping a tail gives a head.