I need to find all permutations of 3 elements from {a,b,c,d,e} with this condition: These must include element d maximum once, and a must be before c. I'm using the following code and I don't know how to set the condition. Anyone help :)

Permutations[list, {3}];
perm[a_, b_, c_, d_, e_] := Module[{perm},
   list = {a, b, c, d, e};
    k = Tuples[list, 3];
  • $\begingroup$ Are you sure you did your homework? A Permutation is per definition a rearrangement of members from a set. When your set {a,b,c,d,e} contains only one d, then there is no way it can ever have more than one d in all existing permutations. Can you clear what exactly you mean? $\endgroup$
    – halirutan
    May 4, 2015 at 3:04

1 Answer 1


I interpret your query differently from kguler - I believe you're after this:

result = Select[Tuples[{a, b, c, d, e}, 3], 
   Count[#, d] <= 1 && ! MatchQ[#, {___, c, ___, a, ___}] &];

result // Short

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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