4
$\begingroup$

I want to start with:

{a,b},{c,d},{e,f}

and end up with:

{a,c,e},{a,c,f},{a,d,e},{a,d,f},{b,c,e},{b,c,f},{b,d,e},{b,d,f}

then do every ordering of each:

{a,c,e},{a,e,c},{c,a,e},{c,e,a},{e,a,c},{e,c,a},{a,c,f},{a,f,c},etc.

I believe Tuples combined with Permutations maybe are the way to go, but unsure how to do this.

| improve this question | | | | |
$\endgroup$
6
$\begingroup$

Figured it out. Was easier than I thought:

set={{a,b},{c,d},{e,f}};
set2=Map[Permutations,Tuples[set]]

{{{a,c,e},{a,e,c},{c,a,e},{c,e,a},{e,a,c},{e,c,a}},
{{a,c,f},{a,f,c},{c,a,f},{c,f,a},{f,a,c},{f,c,a}},
{{a,d,e},{a,e,d},{d,a,e},{d,e,a},{e,a,d},{e,d,a}},
{{a,d,f},{a,f,d},{d,a,f},{d,f,a},{f,a,d},{f,d,a}},
{{b,c,e},{b,e,c},{c,b,e},{c,e,b},{e,b,c},{e,c,b}},
{{b,c,f},{b,f,c},{c,b,f},{c,f,b},{f,b,c},{f,c,b}},
{{b,d,e},{b,e,d},{d,b,e},{d,e,b},{e,b,d},{e,d,b}},
{{b,d,f},{b,f,d},{d,b,f},{d,f,b},{f,b,d},{f,d,b}}}
| improve this answer | | | | |
$\endgroup$
2
$\begingroup$

You can also use Distribute:

set3 = Distribute[set, List, List, List, Permutations[{##}] &] ;
set3 == set2

True

| improve this answer | | | | |
$\endgroup$

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.