seco

Hi
i have an array like this

groupid number
1 235
2 987
3 781
4 879
and so on .....

and i want to make a combination of groups that has sum between say 1000 and 1500 or what ever

how to iterate through all possible combinations of all items (i mean if i have 10 groups it will be 10 power 10 combinations right ) so how to do that

thanks in advance.


Re: Visual Basic Express Edition how to make possible combinations of numbers

jgalley

Hi,

There are several potential problems you might be asking for help with. Are you looking for a way to generate all combinations of the members in a collection If so, must combinations use all members of the collection Is ordering important

A separate but related problem might be a question of optimization, that is generate all subsets of elements where the sum(number) between 1000 and 1500





Re: Visual Basic Express Edition how to make possible combinations of numbers

js06

This an example that will get each item in the array and then add it to all items in the array 1 at a time.

if they match your range in the textboxes then it will show the results in a listbox. I had 2 listboxes for testing.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Me.ListBox1.Items.Clear()

Me.ListBox2.Items.Clear()

Dim lowrange As String = Me.TextBox1.Text

Dim highrange As String = Me.TextBox2.Text

Dim result As Integer = 0

Dim numlist() As Integer = {100, 200, 300, 400}

For x As Integer = 0 To numlist.Length - 1

Me.ListBox1.Items.Add(numlist(x))

For i As Integer = 0 To numlist.Length - 1

If Integer.TryParse(lowrange, Me.TextBox1.Text) Then

If Integer.TryParse(highrange, Me.TextBox2.Text) Then

result = numlist(x) + numlist(i)

If result >= lowrange And result <= highrange Then

Me.ListBox2.Items.Add(numlist(x) & " + " & numlist(i) & " = " & result)

End If

End If

End If

Next

Next

End Sub






Re: Visual Basic Express Edition how to make possible combinations of numbers

seco

thanks for reply

yes i want to generate all possible combinations of numbers in te collection and must use all members of the collection and start from the first element with second one and get thousands and thousands of combinations and ordering is not important

those generated combinations i will get the sum of every one of them and check if it is between 2 specific numbers or not.

by the way the code that js06 writes only givres combinations between every two elements of the collection and i want all possible combinations.

thanks.




Re: Visual Basic Express Edition how to make possible combinations of numbers

js06

I guess i misunderstood what you were looking for.

But i am curious, what would you use these results for

What prupose does it serve to get these combinations






Re: Visual Basic Express Edition how to make possible combinations of numbers

jgalley

Sorry, I am still a little confused. Let's try this.. with the input as:

groupid number
1 235
2 987
3 781

What would the expected output be

A)

235, 987, 781

235, 781, 987

987, 235, 781

987, 781, 235

781, 987, 235

781, 235, 987

B)

235

987

781

235, 987

235, 781

235, 987, 781

235, 781, 987

987, 235

987, 781

987, 235, 781

987, 781, 235

781, 235

781, 987

781, 235, 987

781, 987, 235

C) Something Else





Re: Visual Basic Express Edition how to make possible combinations of numbers

Martin Xie - MSFT

We are changing the issue type to ˇ°Commentˇ± because you have not followed up with the necessary information.

If you have more time to look at the issue and provide more information, please feel free to change the issue type back to ˇ°Questionˇ± by editing your initial post and changing the radio button at the top of the post editor window.

If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions.


Thank you!






Re: Visual Basic Express Edition how to make possible combinations of numbers

PaulAnthony

Hi,

Along the lines of this, I am trying to write an algorithm which does something very similar. It is to process some financial information where I am trying to match the value on one to document to any possible unique combinations of values of another set of documents. For example if the numbers 1, 2, 3, 4 were entered (groupid in the above example) - I would want to generate the unique combinations (I think this is complete) of values below:

1

1,2

1,3

1,4

1,2,3

1,2,4

1,3,4

1,2,3,4

2

2,3

2,4

2,3,4

3

3,4

4

Can anyone help