Message Boards Message Boards

0
|
12624 Views
|
5 Replies
|
5 Total Likes
View groups...
Share
Share this post:

How to make a list of the possible pairs of 4 objects from a set of 6?

Example: set of 6 objects =( a, b, c, d, e, f)
2 possible pair coming from 4 objects from the set: ab, ec .
No repetitions allowed.
ab and ba have to be considered as different pairs

Thanks in advance!
regards
lorenzo

POSTED BY: Lorenzo Galante
5 Replies

Hi Lorenzo,

my idea goes like this:

  • calculate all permutations;
  • make 3 pairs of every permutation;
  • take only the first two pairs into account (using Most);
  • delete the duplicates; two elements are considered as duplicates, when foo[x1,x2]+foo[y1,y2] gives identical expressions. "foo" is basically NOT orderless, otherwise left undefined.

As typical for Mathematica the code is very much shorter than any explanation:

ClearAll["Global`*"]
objects = {a, b, c, d, e, f};
DeleteDuplicatesBy[
 Most /@ (Partition[#, 2] & /@ Permutations[objects]), 
 foo @@ #[[1]] + foo @@ #[[2]] &]

Hope I am correct ...

Henrik

POSTED BY: Henrik Schachner

Thankyou Henrik. But I expected only 360 pairs. Your computation gives me too many pairs. bye lorenzo

POSTED BY: Lorenzo Galante

Hi Lorenzo,

my code gives exactly 180 pairs (of pairs)! That is because e.g. {{a,b},{c,d}} and {{c,d},{a,b}} are considered identical - in contrast to Davids solution. It depends on what you want.

Cheers Henrik

POSTED BY: Henrik Schachner

How about this:

set = {a, b, c, d, e, f}
step1 = Subsets[set, {4}]
step2 = Flatten[Permutations /@ step1, 1];
Partition[#, 2] & /@ step2

giving:

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

Thanks a lot! regards lorenzo

POSTED BY: Lorenzo Galante
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract