Delete from list
How can I delete the vectors wich have two or more 'b','c','d' ?
(lst = DeleteDuplicates[Map[Sort, Tuples[{a, b, c, d}, 3]]]) // Grid
Create the pattern to delete
tst=Flatten[Permutations[{#,#,_},{3}]&/@{b,c,d},1]
Delete them. I do not know now how to map/reset DeleteCases
, so used a Do
Do[lst= DeleteCases[lst,tst[[n]]],{n,1,Length@tst}]
lst // Grid
Pick[lst, Max[Function[{x}, Count[#, x]] /@ {b, c, d}] <= 1 & /@ lst] // Grid
Update: A variation on @Shadowray's suggestion to construct the desired list directly:
PadLeft[Subsets[{b, c, d}], Automatic, a]
(* or PadLeft[Subsets[{b, c, d}]] /. 0 -> a *)
{{a, a, a}, {a, a, b}, {a, a, c}, {a, a, d}, {a, b, c}, {a, b, d}, {a, c, d},{b, c, d}}
Update 2: Also
DeleteDuplicates@Subsets[{a, a, a, b, c, d}, {3}]
{{a, a, a}, {a, a, b}, {a, a, c}, {a, a, d}, {a, b, c}, {a, b, d}, {a, c, d},{b, c, d}}
Here is a fairly clean approach. By naming the pattern b | c | d
(|
is the short form of Alternatives
) we force a match for the same letter each time.
m = DeleteDuplicates[Map[Sort, Tuples[{a, b, c, d}, 3]]];
m2 = DeleteCases[m, {___, x : b|c|d, x_, ___}]
m2 // Grid
$\begin{array}{ccc} a & a & a \\ a & a & b \\ a & a & c \\ a & a & d \\ a & b & c \\ a & b & d \\ a & c & d \\ b & c & d \\ \end{array}$