0
$\begingroup$

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

$\endgroup$
4
  • $\begingroup$ DeleteDuplicatesBy[ldppp, Sort]? $\endgroup$
    – Kuba
    Jan 26, 2018 at 21:46
  • $\begingroup$ I thought must be simple but stay focused en DeleteCases... feel like the skier who bumps in the only tree in the track! thanks @Kuba $\endgroup$ Jan 26, 2018 at 21:51
  • $\begingroup$ No worries. p.s. just leaving another closely related: mathematica.stackexchange.com/q/140571/5478 $\endgroup$
    – Kuba
    Jan 26, 2018 at 21:59
  • $\begingroup$ DeleteCases[{{a,b},{a,c},{b,a}}, {a,b}|{b,a}] gives you {a,c} if that helps $\endgroup$
    – Bill
    Jan 26, 2018 at 23:04

0

Browse other questions tagged or ask your own question.