4
$\begingroup$

This question already has an answer here:

Given the matrix:

A := {{a, a, a}, {a, a, b}, {a, a, c}, {a, a, d}, {a, b, a}, {a, b, b}, {a, b, c}, {a, b, d}, 
      {a, c, a}, {a, c, b}, {a, c, c}, {a, c, d}, {a, d, a}, {a, d, b}, {a, d, c}, {a, d, d}, 
      {b, a, a}, {b, a, b}, {b, a, c}, {b, a, d}, {b, b, a}, {b, b, b}, {b, b, c}, {b, b, d}, 
      {b, c, a}, {b, c, b}, {b, c, c}, {b, c, d}, {b, d, a}, {b, d, b}, {b, d, c}, {b, d, d}, 
      {c, a, a}, {c, a, b}, {c, a, c}, {c, a, d}, {c, b, a}, {c, b, b}, {c, b, c}, {c, b, d}, 
      {c, c, a}, {c, c, b}, {c, c, c}, {c, c, d}, {c, d, a}, {c, d, b}, {c, d, c}, {c, d, d}, 
      {d, a, a}, {d, a, b}, {d, a, c}, {d, a, d}, {d, b, a}, {d, b, b}, {d, b, c}, {d, b, d}, 
      {d, c, a}, {d, c, b}, {d, c, c}, {d, c, d}, {d, d, a}, {d, d, b}, {d, d, c}, {d, d, d}}

writing:

DeleteDuplicates[A, Total[#1] == Total[#2] &]

I get:

{{a, a, a}, {a, a, b}, {a, a, c}, {a, a, d}, {a, b, b}, {a, b, c}, {a, b, d}, {a, c, c}, {a, c, d}, {a, d, d}, 
 {b, b, b}, {b, b, c}, {b, b, d}, {b, c, c}, {b, c, d}, {b, d, d}, {c, c, c}, {c, c, d}, {c, d, d}, {d, d, d}}

Now, I would write:

DeleteDuplicates[A, "??" &]

and obtain:

{{a, b, c}, {a, b, d}, {a, c, b}, {a, c, d}, {a, d, b}, {a, d, c}, {b, a, c}, {b, a, d},
 {b, c, a}, {b, c, d}, {b, d, a}, {b, d, c}, {c, a, b}, {c, a, d}, {c, b, a}, {c, b, d},
 {c, d, a}, {c, d, b}, {d, a, b}, {d, a, c}, {d, b, a}, {d, b, c}, {d, c, a}, {d, c, b}}

What should I write instead of "??"

Thank you.

$\endgroup$

marked as duplicate by Feyre, MarcoB, corey979, Quantum_Oli, m_goldberg Feb 8 '17 at 2:30

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    $\begingroup$ Select[A, Length[Union[#]] == 3 &]? $\endgroup$ – Quantum_Oli Feb 7 '17 at 16:06
  • 1
    $\begingroup$ I'm not sure DeleteDuplicates is actually what you want! (See my above comment). As an aside, if you desire to directly generate your results you can do Permutations[{a, b, c, d}, {3}] $\endgroup$ – Quantum_Oli Feb 7 '17 at 16:10
  • $\begingroup$ related also related also related $\endgroup$ – Feyre Feb 7 '17 at 16:21
6
$\begingroup$

You want to use Select on the list of vectors. Then you can use DuplicateFreeQ:

ClearAll[desired];
desired = {{a, b, c}, {a, b, d}, {a, c, b}, {a, c, d}, {a, d, b}, {a, d, c},
           {b, a, c}, {b, a, d}, {b, c, a}, {b, c, d}, {b, d, a}, {b, d, c},
           {c, a, b}, {c, a, d}, {c, b, a}, {c, b, d}, {c, d, a}, {c, d, b},
           {d, a, b}, {d, a, c}, {d, b, a}, {d, b, c}, {d, c, a}, {d, c, b}};
Select[A, DuplicateFreeQ] === desired
(* True *)

If you have a pre-10.0 version of Mathematica, DuplicateFreeQ is equivalent to

Pillsy`DuplicateFreeQ[list_] := list === DeleteDuplicates[list];
$\endgroup$
  • $\begingroup$ WoW, another way! Thank you too! $\endgroup$ – TeM Feb 7 '17 at 16:15
3
$\begingroup$

If you are looking for alternative ways: Alternatives maybe your friend ;-)

First:

rule = Alternatives @@ (Permutations@{x_, y_, x_}) :> Nothing

then

A /. rule
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.