Solved

All combinations of an List with integers

Posted on 2014-04-13
4
164 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Question! 4 38
Printing 1 58
Add different cell to otherwise similiar row 4 45
JQuery Detecting page post back 6 8
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

839 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