?
Solved

All combinations of an List with integers

Posted on 2014-04-13
4
Medium Priority
?
168 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 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

Industry Leaders: 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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

752 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