Задача на множества
Код:
domains
list=integer*
predicates
peresech(list,list,list)
union(list,list,list)
member(integer,list)
goal
clearwindow,
write("Pervoe mnozestvo: "),nl,readterm(list,A),
write("Vtoroe mnozestvo: "),nl,readterm(list,B),
write("Tretie mnozestvo: "),nl,readterm(list,C),
peresech(A,B,AB),
union(AB,C,ABC),
write("Poluch mnozhestv"), nl,
write(ABC).
clauses
peresech([],_,[]).
peresech([H|T1],S2,[H|T]):-member(H,S2),!,
peresech(T1,S2,T).
peresech([_|T],S2,S):-peresech(T,S2,S).
union([],S2,S2).
union([H|T],S2,S):-member(H,S2),!,
union(T,S2,S).
union([H|T],S2,[H|S]):-union(T,S2,S).
member(H,[H|_]).
member(X,[_|Tail]):-member(X,Tail).
list=integer*
predicates
peresech(list,list,list)
union(list,list,list)
member(integer,list)
goal
clearwindow,
write("Pervoe mnozestvo: "),nl,readterm(list,A),
write("Vtoroe mnozestvo: "),nl,readterm(list,B),
write("Tretie mnozestvo: "),nl,readterm(list,C),
peresech(A,B,AB),
union(AB,C,ABC),
write("Poluch mnozhestv"), nl,
write(ABC).
clauses
peresech([],_,[]).
peresech([H|T1],S2,[H|T]):-member(H,S2),!,
peresech(T1,S2,T).
peresech([_|T],S2,S):-peresech(T,S2,S).
union([],S2,S2).
union([H|T],S2,S):-member(H,S2),!,
union(T,S2,S).
union([H|T],S2,[H|S]):-union(T,S2,S).
member(H,[H|_]).
member(X,[_|Tail]):-member(X,Tail).
Код:
domains
list=integer*
predicates
peresech(list,list,list)
union(list,list,list)
member(integer,list)
goal
clearwindow,
write("Pervoe mnozestvo: "),nl,readterm(list,A),
write("Vtoroe mnozestvo: "),nl,readterm(list,B),
write("Tretie mnozestvo: "),nl,readterm(list,C),
peresech(A,B,AB),
union(AB,C,ABC),
write("Poluch mnozhestv"), nl,
write(ABC).
clauses
peresech([],_,[]).
peresech([H|T1],S2,[H|T]):-member(H,S2),!,
peresech(T1,S2,T).
peresech([_|T],S2,S):-peresech(T,S2,S).
union([],S2,S2).
union([H|T],S2,S):-member(H,S2),!,
union(T,S2,S).
union([H|T],S2,[H|S]):-union(T,S2,S).
member(H,[H|_]).
member(X,[_|Tail]):-member(X,Tail).
list=integer*
predicates
peresech(list,list,list)
union(list,list,list)
member(integer,list)
goal
clearwindow,
write("Pervoe mnozestvo: "),nl,readterm(list,A),
write("Vtoroe mnozestvo: "),nl,readterm(list,B),
write("Tretie mnozestvo: "),nl,readterm(list,C),
peresech(A,B,AB),
union(AB,C,ABC),
write("Poluch mnozhestv"), nl,
write(ABC).
clauses
peresech([],_,[]).
peresech([H|T1],S2,[H|T]):-member(H,S2),!,
peresech(T1,S2,T).
peresech([_|T],S2,S):-peresech(T,S2,S).
union([],S2,S2).
union([H|T],S2,S):-member(H,S2),!,
union(T,S2,S).
union([H|T],S2,[H|S]):-union(T,S2,S).
member(H,[H|_]).
member(X,[_|Tail]):-member(X,Tail).