# Permutations with conditions: element a to appear before c

GROUPS:
 Hello!i need to calculate something in Mathematica; We have the list A = {a,b,c,d,e} I need to find all permutations which will contain exactly 3 elements from A in which: element b appears only once (or does not appear at all) if a and c appear, a will always appear before c So far i have: A={a,b,c,d,e}; Select[Tuples[A, 3], OrderedQ] But it seems i'm missing quite a lot .. Any help will be appreciated. Thanks!
3 years ago
3 Replies
 There might be a clever way to do this, but let's focus on defining functions that test your two properties testA[list_] := Count[list, b]<2 testB[list_] := If[MemberQ[list, a] && MemberQ[list, b], First@FirstPosition[list, a] < First@FirstPosition[list, b], True] You can use these functions with Select
3 years ago
 A couple of ways come to mind. Both delete the cases that are not wanted from the output of the permutation generator. aa = {a, b, c, d, e}; p1 = DeleteCases[ Tuples[{aa, aa, aa}], {___, c, ___, a, ___} | {___, b, ___, b, ___}]; bb = {a, a, a, b, c, c, c, d, d, d, e, e, e}; p2 = DeleteCases[Permutations[bb, {3}], {___, c, ___, a, ___}]; p1 and p2 are the same list.
1 year ago
 I believe this works too Clear[a, b, c, d, e]; Sort /@ Select[Tuples[{a, b, c, d, e}, {3}], Count[#, b] <= 1 &]