Advertisement
steffffffan

P2_5

Nov 20th, 2022
839
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 0.49 KB | None | 0 0
  1. % 5.
  2. % a) Sa se determine pozitiile elementului maxim dintr-o lista liniara.
  3. % De ex: poz([10,14,12,13,14], L) va produce L = [2,5].
  4.  
  5. elmax([],0):-!.
  6. elmax([H],H):-!.
  7. elmax([H|T],H):- elmax(T,MT), H>=MT,!.
  8. elmax([H|T],MT):-elmax(T,MT), H=<MT.
  9.  
  10.  
  11. pozh([],[],_,_).
  12. pozh([H|T],R,I,X):-
  13.     H=X,
  14.     I1 is I+1,
  15.     pozh(T,R1,I1,X),
  16.     R=[I|R1].       % ii incarcam pozitia
  17. pozh([H|T],R,I,X):-
  18.     H\=X,
  19.     I1 is I+1,
  20.     pozh(T,R,I1,X).
  21.  
  22. poz(L,R):-
  23.     elmax(L,M),
  24.     pozh(L,R,1,M).
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement