0

Lets say i have an array with 3 numbers:

[1,2,3]

I want to find all combinations of this 3 numbers where all the numbers are included.

Output should look like this:

[1,2,3], [1,3,2], [3,1,2], [3,2,1], [2,3,1], [2,1,3]
3
  • stackoverflow.com/questions/42773836/…. Commented Jul 1, 2020 at 2:03
  • i need only combinations including all 3 numbers and also i need any given combination of them. 3,2,1 ≠ 1,2,3. Also i dont need 1,1,2 or 1,2,2 etc. Every number can only occure once. Commented Jul 1, 2020 at 2:07
  • stackoverflow.com/a/9960925/636077 Commented Jul 1, 2020 at 2:12

1 Answer 1

0

It's a bit brute force, but if you're only going to have to do this for a list of three elements, this is simple enough.

a = [1, 2, 3]
a_comb = [[a[0],a[1],a[2]], [a[0], a[2], a[1]], [a[2], a[0], a[1]], [a[2], a[1], a[0]], [a[1],a[0],a[2]], [a[1],a[2],a[0]]]
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.