Помогите пожалуйста доделать программу!
Среда: Visual Prolog Personal Edition v 5.1-5.2
Дано: список второго уровня с маркерами ("п")
Задача № 1: выделить списки с учётом маркера (разбить на подсписки имеющийся список) - выполнено
Задача № 2: полученные списки собрать в список второго уровня разделяя маркером (как было…) – не получается :upset:
конкретно не получается предикат «набор1(А)» который, по идее, должен склеивать уже промаркированные списки.
DOMAINS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%----------------------------------------------------------------------------
i_list=integer*
s_list=symbol*
%----------------------------------------------------------------------------
PREDICATES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%----------------------------------------------------------------------------
nondeterm conc(s_list,s_list,s_list)
nondeterm list(s_list)
nondeterm перебор_s_list_2(s_list,s_list)
nondeterm перебор(s_list)
nondeterm набор(s_list)
nondeterm набор1(s_list)
%----------------------------------------------------------------------------
CLAUSES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%----------------------------------------------------------------------------
conc([],L,L).
conc([H|T],L,[H|T1]):-conc(T,L,T1).
%----------------------------------------------------------------------------
list([п,"1","2","3",п,"4","5","6",п,"7","8","9",п]).
%----------------------------------------------------------------------------
перебор_s_list_2(А,X1):-conc(_,["п"|R],А),conc(_,["п"|R1],R),conc(X,R1,R),conc(X1,["п"],X),not(conc(_,["п"|_],X1)).
%----------------------------------------------------------------------------
перебор(X):-list(А),перебор_s_list_2(А,X).
%----------------------------------------------------------------------------
набор(["п"]).
набор(А):-перебор(X),conc(X,["п"],А).
%----------------------------------------------------------------------------
набор1(В):-набор(Б),набор1(А),conc(А,Б,В).
%----------------------------------------------------------------------------
GOAL %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%----------------------------------------------------------------------------
набор(А).
%набор1(А).
В данном варианте программа даёт решение:
А=["п"]
А=["1","2","3","п"]
А=["4","5","6","п"]
А=["7","8","9","п"]
4 Solutions
Требуемое решение:
А=["п","1","2","3","п","4","5","6","п","7","8","9","п"]
1 Solutions
Заранее благодарен.
|