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$

1 Answer 1

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$
1
  • $\begingroup$ Yes this is perfect! Thank you very much. $\endgroup$ Nov 22, 2017 at 9:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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