Complete graph traversal algorithm in Prolog
Consider describing what a transition is:

list_transition(List, (E1-&gt;E2)) :-
        select(E1, List, Rest),
        member(E2, Rest).


Example query:

?- list_transition([0,1,2], T).
T = (0-&gt;1) ;
T = (0-&gt;2) ;
T = (1-&gt;0) ;
T = (1-&gt;2) ;
T = (2-&gt;0) ;
T = (2-&gt;1) ;
false.


And to get all transitions:

?- findall(T, list_transition([0,1,2], T), Transitions).
Transitions = [ (0-&gt;1), (0-&gt;2), (1-&gt;0), (1-&gt;2), (2-&gt;0), (2-&gt;1)].