Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- :- initialization(consult('kinship.pro')).
- pred(X,Y) :- (var(X) ; var(Y)), parent(X,Y).
- pred(X,Y) :- nonvar(X), nonvar(Y), parent(X,Y), !.
- pred(X,Y) :- parent(X,Z), pred(Z,Y).
- bs(X,Y):-
- setof(L,parent(L,X),Lst),
- setof(K,parent(K,Y),Lst),
- X \=Y .
- brother(X,Y):-
- male(X),
- setof(L,parent(L,X),Lst),
- setof(K,parent(K,Y),Lst),
- X \=Y .
- sister(X,Y):-
- female(X),
- setof(L,parent(L,X),Lst),
- setof(K,parent(K,Y),Lst),
- X \=Y .
- married(X,Y):-
- parent(X,Z),parent(Y,Z),
- X \= Y,!.
- husband(X,Y):-
- married(X,Y),
- male(X).
- cousin(X,Y):-
- setof(L,parent(L,X),[H1,H2|T]),
- setof(K,parent(K,Y),[H3,H4|T1]),
- (bs(H1,H3);bs(H1,H4);bs(H2,H3);bs(H2,H4)).
- childrens(X,N):-
- setof(L,parent(X,L),Lst),
- length(Lst,N).
- nephews(Lst,X):-
- setof(L,(cousin(X,Y),parent(Y,L)),Lst).
- family(X):-
- X=[H1,H2|T],
- married(H1,H2),
- setof(L,parent(H1,L),Lst),
- Lst=T.
- %n1 04-06 comp
- comp(El1, El2, Order) :-
- atom(Order),
- Term =.. [Order, El1, El2],
- call(Term).
- %filter
- %фильтруем первый
- filter(Lst1,Lst2,FiltFunc):- %EMPTY l1,l2=TRUE
- Lst1=[],Lst2=[],!.
- filter(Lst1,Lst2,FiltFunc):- %false if
- ((Lst1\=[],Lst2=[]);(Lst1=[],Lst2\=[]),fail).
- filter([H1|T1],Lst2,FiltFunc):- %запускаем терм каждый раз и при его выполнении и совпадении элементов
- Lst2=[H2|T2], %продолжаем
- atom(FiltFunc),
- Term=..[FiltFunc,H1],
- (
- (call(Term),H1=H2,!,filter(T1,T2,FiltFunc)) ;
- filter(T1,Lst2,FiltFunc)
- ).
- %addhead
- addhead(E,Lst1,Lst2):-
- (Lst2=[],Lst1=[],!).
- addhead(E,Lst1,Lst2):-
- Lst1=[H1|T1],
- Lst2=[H2|T2],
- [E|H1]=H2,
- addhead(E,T1,T2).
- %в качестве функции можно подать предикат m
- foldl(X0,_,[],Res):-
- Res=X0,!.
- foldl(X0,F,Lst,Res):-
- Lst=[H|T],
- call(F,X0,H,K),
- foldl(K,F,T,Res).
- m(A,B,C):-
- C is (A-B).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement