0

I need to create a set A={“a”, “b”, “c”, “d” “e”} and print all the permutations of the set with length 3 that satisfy the condition: element "a" has to be ahead of "c" and "d" has to occur at least once.

corey979
  • 23,947
  • 7
  • 58
  • 101
Gorjan
  • 1
  • 1

1 Answers1

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

(*

{{"c", "d", "a"}, {"d", "c", "a"}}

*)

David G. Stork
  • 41,180
  • 3
  • 34
  • 96