I have to find all possible pairs in a list, the following way:
given a list L=[[1,1,1],[1,2,1],[2,1,1],[2,2,1],[3,1,1],[3,2,1]]
[1,1,1] has pairs [1,1],[1,1],[1,1]
[1,2,1] has pairs [1,2],[2,1] because [1,1] was already found
[2,1,1] has pairs [2,1],[2,1] these are not the same because they are located at different positions
[2,2,1] has pairs [2,2] the other pairs have been found
[3,1,1] has pairs [3.1] [3,1]
[3,2,1] has pairs [3,2]
I have a predicate that makes all possible pairs but I doesn't do it this way. I'm new to prolog and I don't know what else to do. This is what I have:
It also returns the number of pairs created
do_pairs(L,PL,N):- do_pairs1(L,[],PL),len(PL,N).
do_pairs1([],L,L) :- !.
do_pairs1([H|T],Pairs,PL):-
pairs(H,P),
do_pairs1(T,[P|Pairs],PL)
.
pairs(L,Pairs):- findall({I-J}, (member(I,L), member(J,L),I=<J), Pairs).