1
$\begingroup$

I have a list with ten elements, for example:

{x1,x2,x3,x4,x5,x6,x7,x8,x9,x10} 

I want to have all the combinations of the 3 elements-list like below:

{{x1,x2,x3},{x1,x2,x4},{x1,x2,x5},.....,{x2,x3,x4},{x2,x3,x5},......} 

I cannot find a function to do this.

$\endgroup$
4
  • 5
    $\begingroup$ Subsets[{x1, x2, x3, x4, x5, x6, x7, x8, x9, x10}, {3}]? $\endgroup$ Commented Nov 24, 2016 at 9:21
  • $\begingroup$ Wait, do you want to allow for permutations, I mean, do you want to have also the combinations {x1,x2,x3} and {x2,x1,x3}? If so, then this might help Select[Permutations[Array[x, 10], 3], Length[#] == 3 &] $\endgroup$ Commented Nov 24, 2016 at 9:32
  • 1
    $\begingroup$ 17242 $\endgroup$ Commented Nov 24, 2016 at 9:33
  • $\begingroup$ @Mauricio Lobos.No, I don't want permutations. just{x1,x2,x3}and other combinations. $\endgroup$ Commented Nov 24, 2016 at 10:28

1 Answer 1

3
$\begingroup$
lst = {x1, x2, x3, x4, x5}; Subsets[lst, {3}] 

{{x1, x2, x3}, {x1, x2, x4}, {x1, x2, x5}, {x1, x3, x4}, {x1, x3, x5}, {x1, x4, x5}, {x2, x3, x4}, {x2, x3, x5}, {x2, x4, x5}, {x3, x4, x5}}

Or, if the order matters,

Permutations[lst, {3}] 

Mathematica graphics

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.