Advertisement
Guest User

Untitled

a guest
Oct 18th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 0.58 KB | None | 0 0
  1. nr_pare([],[]).
  2. nr_pare([H|T],Out):-
  3.     mod(H,2)=:=1,
  4.     nr_pare(T,Out).
  5. nr_pare([H|T],[H|Out]):-
  6.     mod(H,2)=:=0,
  7.     nr_pare(T,Out).
  8.  
  9. nr_impare([],[]).
  10. nr_impare([H|T],Out):-
  11.     mod(H,2)=:=0,
  12.     nr_impare(T,Out).
  13. nr_impare([H|T],[H|Out]):-
  14.     mod(H,2)=:=1,
  15.     nr_impare(T,Out).
  16.  
  17. contopire([],[],[]).
  18. contopire([H1|T1],[H2|T2],[H1|Out]):-
  19.     mod(H1,2)=:=0,
  20.     contopire(T1,[H2|T2],Out).
  21. contopire([],[H2|T2],[H2|Out]):-
  22.    mod(H2,2)=:=1,
  23.    contopire([],T2,Out).  
  24.  
  25. solve(List,Z):-
  26.     nr_pare(List,X),
  27.     nr_impare(List,Y),
  28.     contopire(X,Y,Z).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement