Solved

All combinations of an List with integers

Posted on 2014-04-13
164 Views
Hi

I have a list with up to 8 values in it. (integer)
Now I want to get all combinations of these value's,

so e.g. a List with 3 integers (1,2,3)
I need as result:

1
2
3
1-2
2-3
3-1
1-2-3

what I don't need is 2-1/3-2/1-3, so 1-3 has the same value as 3-1 for me...

How can I do this with dynamic values (so it might be value 4, 12, 17, 3)

Thanks
0
Question by:Ruttensoft
• 2

LVL 100

Expert Comment

ID: 39998875
Do you need the output to be as you show it or do you just need to list of combinations without regard to order?

Consider how you have to loop through the data.

Can you have duplicate values in the list?

What programming constructs can you use?

Have you identified the algorithm you need for this?

mlmcc
0

LVL 25

Accepted Solution

apeter earned 500 total points
ID: 39999192
Looks like you need three for loops.

split it and get an array.

1. Lopp the array and print individual element separately
2. Second one, begins from index I and take I+1 and join them,  this loops until < list.count -1. at the end add list[count],lit[0] as another output
3. You can use list.join for this. no for loop is required
0

LVL 100

Expert Comment

ID: 39999413
WHat about a list of 8 elements like

1,3,5,7,9,11,13,15

mlmcc
0

Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question