I failed to use DeleteCases
to eliminate from a list
of pairs when they are the same {a,b} {a,b} or {a,b} {b,a}. To test finally I wrote the procedure using For
For
and If
and Reap
Saw
to identify the elements that i had to delete ... but I can not found the way this is what I did including the sample generator
Clear["Global`*"]
Remove["Global`*"]
ldp = Range[11, 99];
ldpp = RandomChoice[ldp, 200];
ldppp = Partition[ldpp, 2, 1, -1];
For[i = 1, i < Length[ldppp], i++,
For[j = i + 1, j <= Length[ldppp], j++,
If[Or[ldppp[[i]] == ldppp[[j]],
ldppp[[i]] == Reverse[ldppp[[j]]]], Print[ldppp[[i]], ldppp[[j]]]]
]
]
Reap[
For[i = 1, i < Length[ldppp], i++,
For[j = i + 1, j <= Length[ldppp], j++,
If[Or[ldppp[[i]] == ldppp[[j]],
ldppp[[i]] == Reverse[ldppp[[j]]]],
Sow[{ldppp[[i]], ldppp[[j]]}]]]
]
]
I would appreciate some trick to move to functional style
DeleteDuplicatesBy[ldppp, Sort]
? $\endgroup$DeleteCases[{{a,b},{a,c},{b,a}}, {a,b}|{b,a}]
gives you{a,c}
if that helps $\endgroup$