Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % не работает
- %ПЕРВЫЙ ВАРИАНТ
- searchmax(Lst1,New,K,Res,Len):-
- (Lst1=[],!);
- (Lst1=[H1,H2|T],
- integer(H1),integer(H2),
- ([H2] = [],K1 is K+1,
- ((K1 > Len,!,searchmax([],[],0,[H1|New],K1));
- (K1 =< Len,!,searchmax([],[],0,Res,Len))
- ));
- %ругается в след. строчке на >
- (H2 > H1,K1 is K+1,!,searchmax([H2|T],[H1|New],K1,Res,Len));
- ((K>Len,!,searchmax([H2|T],[],0,New,K));
- (!,searchmax([H2|T],[],0,Res,Len))
- )).
- tooinO(Lst1,Lst2):-
- Len=0,Res=[],
- searchmax(Lst1,[],0,Res,Len),check(Lst2,Res).
- check(Lst1,Lst2):-
- (Lst1=[],Lst2=[],!);
- (Lst1=[H1|T1],Lst2=[H2|T2],H1 is H2,check(T1,T2)).
- %ВТОРОЙ ВАРИАНТ
- searchmax(Lst1,E,New,K,Res,Len):-
- (Lst1=[],!,K1 is K+1,
- ((K1 > Len,!,searchmax([],[],0,New,K1));
- (K1 =< Len,!,searchmax([],[],0,Res,Len))
- ));
- (Lst1=[H|T],
- %ругается в след. строчке на >
- (H1 > E,K1 is K+1,!,searchmax(T,H1,[H1|New],K1,Res,Len));
- ((K>Len,!,searchmax(T,H1,[],0,New,K));
- (!,searchmax(T,E,[],0,Res,Len))
- )).
- tooinO(Lst1,Lst2):-
- Len=0,Res=[],
- Lst1=[H|T],
- searchmax(T,H,[],0,Res,Len),check(Lst2,Res).
- check(Lst1,Lst2):-
- (Lst1=[],Lst2=[],!);
- (Lst1=[H1|T1],Lst2=[H2|T2],H1 is H2,check(T1,T2)).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement