Advertisement
javatlacati

eliminar elementos de lista de lista

Feb 25th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 0.51 KB | None | 0 0
  1. tiene_alergia(pepe, amoxicilina).
  2. tiene_alergia(pepe, ampicilina).
  3.  
  4. contiene(clamoxil, amoxicilina).
  5. contiene(britapen, ampicilina).
  6.  
  7. posicion(Elemento,List, Posicion):- nth0(Posicion,List,Elemento).
  8.  
  9. insertar(X, 0, L2, [X|L2]).
  10. insertar(X, Pos, [C|R], [C|R2]) :- Pos1 is Pos -1, insertar(X, Pos1, R, R2).
  11.  
  12. borrar(I, L, L2) :- insertar(_,I,L2,L).
  13.  
  14. eliminar(_,[],[]).
  15. eliminar(X, L1, L2) :- posicion(X, L1,Pos), borrar(Pos, L1, L2).
  16. eliminar([X|Xs], L1, L2):- eliminar(X, L1, L3), eliminar(Xs, L3, L2).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement