Solved

All combinations of an List with integers

Posted on 2014-04-13
4
162 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
4 Comments
 
LVL 100

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 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

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


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

mlmcc
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video discusses moving either the default database or any database to a new volume.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

747 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now