0

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];
     perm];
Nasi Jofce
  • 21
  • 2
  • 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? – halirutan May 04 '15 at 03:04

1 Answers1

3

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

ciao
  • 25,774
  • 2
  • 58
  • 139