Advertisement
steffffffan

P2_9

Nov 20th, 2022
868
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 0.47 KB | None | 0 0
  1. %9.
  2. %a) Dandu-se o lista liniara numerica, sa se stearga toate secventele de
  3. % valori consecutive. Ex: sterg([1, 2, 4, 6, 7, 8, 10], L) va produce
  4. % L=[4,10].
  5.  
  6. del([],[]).
  7. del([H],[H]):-!.
  8. del([H1,H2],[]):- 1 is H2-H1,!.
  9. del([H1,H2],[H1,H2]):-not(1 is H2-H1),!.
  10. del([H1,H2,H3|T],R):- 1 is H2-H1, 1 is H3-H2, !,
  11.     del([H2,H3|T],R).
  12. del([H1,H2,H3|T],R):-1 is H2-H1, not(1 is H3-H2),!,
  13.     del([H3|T],R).
  14. del([H1,H2|T],[H1|R]):- not(1 is H2-H1),
  15.     del([H2|T],R).
  16.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement