Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

All combinations of an List with integers

Posted on 2014-04-13
4
Medium Priority
?
170 Views
Last Modified: 2014-05-31
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
Comment
Question by:Ruttensoft
  • 2
3 Comments
 
LVL 101

Expert Comment

by:mlmcc
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

by:
apeter earned 1500 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 101

Expert Comment

by:mlmcc
ID: 39999413
WHat about a list of 8 elements like


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

mlmcc
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question