Advertisement
steffffffan

P2_11

Nov 20th, 2022
993
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 0.36 KB | None | 0 0
  1. % 11.
  2. % a) Se da o lista de numere intregi. Se cere sa se scrie de 2 ori in
  3. % lista fiecare numar prim.
  4.  
  5. primh(1,_):-fail(), !.
  6. primh(_,1):-!.
  7. primh(X,D):- X>1, not(0 is X mod D), D1 is D-1, primh(X,D1).
  8.  
  9. prim(X):-X1 is X-1, primh(X,X1).
  10.  
  11. dupprim([],[]).
  12. dupprim([H|T],[H,H|R]):-prim(H),!, dupprim(T,R).
  13. dupprim([H|T],[H|R]):-not(prim(H)), dupprim(T,R).
  14.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement