Advertisement
steffffffan

P2_10

Nov 20th, 2022
864
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 0.42 KB | None | 0 0
  1. %10.
  2. % a) Se da o lista de numere intregi. Se cere sa se adauge in lista dupa
  3. % 1-ul element, al 3-lea element, al 7-lea elemen, al 15-lea element ...
  4. % o valoare data e.
  5.  
  6. adaugh([],_,[],_,_).
  7. adaugh([H|T],E,R,P,P):-
  8.     P2 is 2*P+1,
  9.     I1 is P+1, !,
  10.     adaugh(T,E,R1,I1,P2),
  11.     R=[H,E|R1].
  12. adaugh([H|T],E,R,I,P):-
  13.     I1 is I+1,
  14.     adaugh(T,E,R1,I1,P),
  15.     R=[H|R1].
  16.  
  17. adaug(L,E,R) :- adaugh(L,E,R,1,1).
  18.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement