-


- - . 29


,
.
3. .
domains
s=symbol
list=s*
l2=list*
l3=l2*
l4=l3*
predicates
tgoal(l2)
delete(list,l2,l2)
member(l2,l3)
conc(l4,l4,l4)
after(l2,l2)
solve(l2,l3)
in_width(l4,l3)
new_node(l2,l3,l3)
write_list(l3)
clauses
tgoal([[a,b,c],[],[]]). tgoal([[],[a,b,c],[]]). tgoal([[],[],[a,b,c]]).
after(Stolbs,[Stolb1,[Up1|Stolb2]|Rest]):-
delete([Up1|Stolb1],Stolbs,Stolbs1), delete(Stolb2,Stolbs1,Rest).
delete(X,[X|L],L).
delete(X,[Y|L],[Y|L1]) :- delete(X,L,L1).
member(X,[X|_]).
member(X,[_|Tail]):- member(X,Tail).
conc([],L,L).
conc([X|L1],L2,[X|L3]) :- conc(L1,L2,L3).
solve(Start,Solution) :- in_width([[Start]],Solution).
in_width([[Node|Path]|_],[Node|Path]) :- tgoal(Node).
in_width([[B|Path]|Paths],Solution) :- findall(S, new_node(B,S,Path), NewPaths),
/* NewPaths - [B|Path] */
conc(Paths,NewPaths,Paths1),!, in_width(Paths1,Solution);
in_width(Paths,Solution). % , B
new_node(B,S,Path) :- after(B,B1), not(member(B1,[B|Path])), S=[B1,B|Path].
write_list([X|Rest]):-write("\n",X),readchar(_), write_list(Rest).
write_list([]).
goal
solve([[c,a,b],[],[]],Solution), write_list(Solution).
6.4.
1. , . (,
.)
2. .



- -  - -  - -