0
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ Gorjan, I am having second thought about my answer. Do you mean that "a" and "c" have to always be present in the result, or that if they are both present, then "a" should come before "c"? $\endgroup$ – MarcoB May 20 '15 at 18:24
  • $\begingroup$ im really not sure $\endgroup$ – Gorjan May 20 '15 at 18:29
  • $\begingroup$ Hmm. If you don't know what problem you want to solve, then it's quite hard to solve it... $\endgroup$ – MarcoB May 20 '15 at 18:31
  • $\begingroup$ i think the result should be {a,c,d}{d,a,c}{a,d,c} $\endgroup$ – Gorjan May 20 '15 at 18:36
1
$\begingroup$
Select[Tuples[{"a", "b", "c", "d", "e"}, 3], 
 Count[#, "d"] == 1 && MatchQ[#, {___, "c", ___,  "a"}] &]

(*

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

*)

$\endgroup$
  • $\begingroup$ I think this was it ty! $\endgroup$ – Gorjan May 20 '15 at 18:42

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