%PR3 Solution Guide: % total: 20 points %Ex3.1 [B] 4 points (2+2) % conc is descrived in section 3.2.2. It is often called "append" conc( [],L,L). conc( [X|L1], L2, [X|L3]) :- conc( L1,L2,L3). % part(a). del3 deletes the last three items from L, producing L1. del3(L,L1) :- conc(L1,[_,_,_],L). %part(b) del3twice deletes the first three and the last three items from L. del3twice(L,L1) :- del3(L,L2), conc([_,_,_],L1,L2). %Ex3.2 [B] 4 points (2+2) % Ex3.2 p.67 % last1(Item,List) holds if Item is the last item in List; it uses conc last1(Item,List) :- conc(_,[Item],List). % conc is descrived in section 3.2.2. It is often called "append" %conc( [],L,L). %conc( [X|L1], L2, [X|L3]) :- conc( L1,L2,L3). % last2(Item,List) holds if Item is the last item in List; it does not use conc last2(Item,[Item]). last2(Item, [_|L]) :- last2(Item,L). %Ex3.4 [B] 3 points % Naive Reverse. rev(X,Y) if list X is the reverse of list Y. rev( [],[]). rev( [X|Y], Z) :- rev( Y,W), conc( W,[X],Z). % See above for conc %Ex3.10 [B] 4 points for either solution %canget(X,Y) if monkey can get banana from state X by doing actions in Y canget( state(_,_,_,has), [ ]). canget( State, [Action|Actions]) :- move( State, Action, NewState), canget( NewState, Actions). %canget(X,Y,Z) if monkey can get banana from state X by doing actions % in Z-Y, in reverse order canget1( state(_,_,_,has), Actions, Actions). canget1( State1, Actions, Path) :- move( State1, Move, State2), canget1( State2, [Move | Actions], Path). % Find the operator declarations: 5 points