/* 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 util. % import cp. import bplan. main => go. go ?=> initial_state(Init), L=new_list(3), % exactly three steps time(bplan(Init,L)), write(L), nl, writeln(len=L.length), fail, nl. go => true. initial_state(Initial) => Initial = [h,h,t]. goal_state(Goal) ?=> writeln($goal_state1(Goal)), Goal = [h,h,h]. goal_state(Goal) => writeln($goal_state2(Goal)),Goal = [t,t,t]. % The three-coins problem formulated for the general planner. % The three possible moves. Each changes one of the coins. legal_move(From, Move, To) ?=> From=[X,Y,Z],Move=flip_left,To=[X1,Y,Z], opposite(X,X1). legal_move(From, Move, To) ?=> From=[X,Y,Z],Move=flip_middle,To=[X,Y1,Z], opposite(Y,Y1). legal_move(From, Move, To) => From=[X,Y,Z],Move=flip_right,To=[X,Y,Z1], 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.