0

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?

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
Kagaratsch
  • 11,955
  • 4
  • 25
  • 72

1 Answers1

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