Can you help me with this problem of backtracking in Prolog?
The string a1, ..., an
is given and it consists of distinct integers.
It is required to display all sub-sets with aspect of "mountain"
(a set has a "mountain" aspect if the elements increase to a certain
point and then decrease).
Eg. 10 16 27 18 14 7.
I know how to verify if a set has mountain aspect...
but now I need to display all solutions :(
% munte(list,integer,integer)
% rezolvare(list)
munte([],2,_).
munte([H|[]],2,_).
munte([H|[H1|T]],Pas,Nr):-
Pas = 1,
H<H1,!,
L=[H1|T],
Nr1=Nr+1,
munte(L,Pas,Nr1).
munte([H|[H1|T]],Pas,Nr):-
Pas = 1,
H>H1,
Nr>1,!,
L=[H1|T],
Pas1=Pas + 1,
Nr1=Nr+1,
munte(L,Pas1,Nr1).
munte([H|[H1|T]],Pas,Nr):-
Pas = 2,
H>H1,!,
L=[H1|T],
Nr1=Nr+1,
munte(L,Pas,Nr1).
rezolvare(L1):-munte(L1,1,1).