5
$\begingroup$

I have two sets

set1 = {2, 3, 4, 5};
set2 = {1, 3, 4, 5};

and I make permutations of them:

permutationsSet1 = DeleteDuplicates[Map[Sort, Permutations[set1, {2}]]];
permutationsSet2 = DeleteDuplicates[Map[Sort, Permutations[set2, {2}]]];

These commands yield

{{2, 3}, {2, 4}, {2, 5}, {3, 4}, {3, 5}, {4, 5}}
{{1, 3}, {1, 4}, {1, 5}, {3, 4}, {3, 5}, {4, 5}}

What I would like to do next is find all the possible combinations between permutationSet1 and permutationSet2 as follows:

{{2,3,1,3}, {2,3,1,4}, {2,3,1,5}, {2,3,3,4}, ..., {4,5,3,4}, {4,5,3,5}, {4,5,4,5}}

Finally, if possible, delete the repetitions in each tuple, e.g.

{{2,3,1}, {2,3,1,4}, {2,3,1,5}, {2,3,4}, ..., {4,5,3}, {4,5,3}, {4,5}}

and get the length of each tuple, e.g.

{3, 4, 4, 3, ..., 3, 3, 2}.

Thanks for your help.

$\endgroup$
6
$\begingroup$

Does this fit your needs?

Length /@ DeleteDuplicates /@ Flatten /@ Tuples[
  Subsets[#, {2}] & /@ {{2, 3, 4, 5}, {1, 3, 4, 5}}
]

{3, 4, 4, 3, 3, 4, 4, 3, 4, 3, 4, 3, 4, 4, 3, 4, 3, 3, 3, 3, 4, 2, 3, 3, 3, 4, 3, 3, 2, 3, 4, 3, 3, 3, 3, 2}

$\endgroup$
  • $\begingroup$ Yes this is perfect! Thank you very much. $\endgroup$ – Laurent Hayez Nov 22 '17 at 9:11

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.