0
$\begingroup$

Consider a list with an even number of elements, e.g.

list = {1,2,3,4};

I would like to have a function fun that produces all possible ways the elements could be arranged in unordered groups of two, so that for example

fun[list]

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

While for the example of length 4 above the decomposition is kind of trivial, for longer examples it becomes more cumbersome. Is there a way to do this efficiently in Mathematica?

$\endgroup$
0
$\begingroup$
DeleteDuplicates[
 Sort[
 (Sort /@ Partition[#, 2] & /@ Permutations[list, {Length[list]}])]
 ]
$\endgroup$
  • $\begingroup$ This produces way too many elements. But the answer to the question linked by Carl Woll seems to do the trick. $\endgroup$ – Kagaratsch Mar 28 '18 at 23:06

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