prologcliqueclique-problem

Access to a number and a vector of an String in Prolog


I have to do the clique problem where the graph is defined like that:

[1-[2,3,4,5,6], 2-[1,3,4,5,6], 3-[1,2,4,5,6],4-[1,2,3,5,6], 5-[1,2,3,4,6], 6-[1,2,3,4,5]]

so I started to do this

c(_,[]).
c(G,X):-length(G,S),rest(X, G, G1).



rest(X, [X|Ys], Ys).
rest(X, [_|Ys], Zs):-rest(X, Ys, Zs).

And i receive:

S = 6-[1,2,3,4,5] ;
S = 5-[1,2,3,4,6] ;
S = 4-[1,2,3,5,6] ;
S = 3-[1,2,4,5,6] ;
S = 2-[1,3,4,5,6] ;
S = 1-[2,3,4,5,6] ;
S = [] ;
parsing query: c([1-[2,3,4,5,6],2-[1,3,4,5,6],3-[1,2,4,5,6],4-[1,2,3,5,6],5-[1,2,3,4,6],6-[1,2,3,4,5]],S) ok!

So i'm trying to get the first element of each iteration (1,2,3,4,5,6), and later the pairs... but don't know how to access to each element.


Solution

  • Doing that:

    rest(X1, [X1-X2|Ys], Ys).
    rest(X, [_|Ys], Zs):-rest(X, Ys, Zs).
    

    Can obtain the first element