SHARE
TWEET

Untitled

a guest Apr 19th, 2019 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. %se um elemento pertence a uma lista
  2. pertence(X,[X|_]).
  3. pertence(X,[_|T]):-pertence(X,T).
  4. %?-pertence(0, [1,2,3,4,5]).
  5.  
  6. %Numero de ocorrencias de um elemento na lista
  7. conta(_,[],0).
  8. conta(X,[X|T], N):-conta(X,T,N1), N is 1 + N1.
  9. conta(X,[_|T], N):-conta(X,T,N).
  10.  
  11. %?-conta(1,[1,2,3,1,5]).
  12.  
  13. % SE A ARESTA PERCENCE AO GRAFO
  14. aresta(a(X,Y), [a(X,Y)|T]).
  15. aresta(a(X,Y), [a(Y,X)|T]).
  16. aresta(a(X,Y), [H|T]):- aresta(a(X,Y), T).
  17.  
  18. earesta(a(X,Y), grafo(Vs, As)):- aresta(a(X,Y), As).
  19. %?-earesta(a(a,b), grafo([a,b,c], [a(b,a),a(c,b),a(c,a)])).
  20. %?-earesta(a(1,2), grafo([1,2,3], [a(2,1), a(3,2), a(3,1)])).
  21.  
  22. %Verifica se a aresta pertence a lista de arestas
  23. verify(X,[X|_]).
  24. verify(X,[_|T]):-pertence(X,T).
  25.  
  26.  
  27. %caminho
  28. caresta([],[]).
  29. caresta([b],[]).
  30. caresta([X,Y|T],[(X,Y)|L]):-caresta([Y|T],L).
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top