|
-
Jan 15th, 2012, 09:05 PM
#1
Thread Starter
Junior Member
Get different combinations
Example:

That's 8 different combinations:
1, X, 1
1, X, X
1, 2, 1
1, 2, X
X, X, 1
X, X, X
X, X, 1
X, 2, X
Trying to figure out a way to get the different combinations depending on the Checked checkboxes into an ArrayList. One entry per possible combination (like the example above).
Note this example is just for 3 games, I will have 13 games in my program so if you click all checkboxes thats 1,6M combinations. Is it really wise to have 1,6M entries in an Array?
I also want to be able to set demands, like: delete all lines in the Array containing two X.
Maybe an ArrayList isn't the way to go?
If you don't have time for code examples please just help me with the thinking
Last edited by stevefox; Jan 15th, 2012 at 09:16 PM.
-
Jan 15th, 2012, 09:33 PM
#2
Re: Get different combinations
the arrayList was superceded by the list(of T) in vb2005
the list(of T) has a removeAll method where you could remove entries you specify
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 15th, 2012, 10:19 PM
#3
Re: Get different combinations
 Originally Posted by stevefox
Is it really wise to have 1,6M entries in an Array?
Not really. But before trying to find out how to store 1,6M individual results, there is another question that goes first:
Why do you think you need to store each result individually? Why not just storing the "ticket" as it is? Any individual result (or all of them) can be readen from it later.
-
Jan 16th, 2012, 09:51 AM
#4
Thread Starter
Junior Member
Re: Get different combinations
 Originally Posted by jcis
Not really. But before trying to find out how to store 1,6M individual results, there is another question that goes first:
Why do you think you need to store each result individually? Why not just storing the "ticket" as it is? Any individual result (or all of them) can be readen from it later.
In the program I just want to show number of combinations minus the conditions the user has set (like most two X). So I thought the best way to set conditions was to create a list.
And later on I want the user to be able to save all the possible combinations into an txt file. 1,6M is never really gonna happen, at most it's gonna be like 30k combinations. So maybe I can set a limit to 30k.
A good start would be to figure out how to get the different combinations into a list. Any tips?
-
Jan 16th, 2012, 07:36 PM
#5
Thread Starter
Junior Member
Re: Get different combinations
I came up with this to get the different combinations. Any comments?
Code:
Dim ckbAllGames As New List(Of String)
Dim allComb As New List(Of String)
For Each game As classGame In collAllGames
Dim str As String = ""
If game.ckb1 = True Then str = "1"
If game.ckb2 = True Then str = str & "X"
If game.ckb3 = True Then str = str & "2"
ckbAllGames.Add(str)
Next
For Each c As Char In ckbAllGames(0)
For Each c2 As Char In ckbAllGames(1)
For Each c3 As Char In ckbAllGames(2)
allComb.Add(c & "," & c2 & "," & c3)
Next
Next
Next
Now I need to loop through and delete all entries in "allComb" that dosn't meet my conditions. Not quite sure how to code this, so an example would be appreciated. Let's say I want to delete all entries In the list that contains two X.
-
Jan 16th, 2012, 09:05 PM
#6
Re: Get different combinations
paul named RemoveAll method that's present in Lists, there is an example Here about how to call RemoveAll with advanced conditions (a shared Function created by you).
Instead of that "EndsWithSaurus" condition in that example, you could use something like..
Code:
Private Shared Function ContainsTwoX(ByVal s As String) As Boolean
If UBound(Split(s, "X")) = 2 Then
Return True
Else
Return False
End If
End Function
then you would be calling this like:
Code:
allComb.RemoveAll(AddressOf ContainsTwoX))
I don't have .Net 2005 so I can't test this code, but if the article is correct this should work fine for you.
Last edited by jcis; Jan 17th, 2012 at 02:15 AM.
-
Jan 17th, 2012, 10:19 AM
#7
Thread Starter
Junior Member
Re: Get different combinations
Thanks, it works fine!
But why UBound?
Another problem, I use a button click event to show all the results in a listbox. I clear the listbox at the top. The first button click gives me the correct combinations but if I change some checkboxes and click the button again I get the same result. I need to restart the program to do a new calculation.
-
Jan 17th, 2012, 01:04 PM
#8
Re: Get different combinations
 Originally Posted by stevefox
Thanks, it works fine!
But why UBound?
It returns the array's upper bound , it's the same than doing..
Code:
If s.Split("X").Length = 3 Then
'...
 Originally Posted by stevefox
Another problem, I use a button click event to show all the results in a listbox. I clear the listbox at the top. The first button click gives me the correct combinations but if I change some checkboxes and click the button again I get the same result. I need to restart the program to do a new calculation.
Your collAllGames collection is being updated correctly with the new values in checkboxes before the process start?
-
Jan 17th, 2012, 01:14 PM
#9
Thread Starter
Junior Member
Re: Get different combinations
Thanks!
Hmm, I have a Private Sub called getGames where I add all the games info to the collAllGames.
I call the sub in the button click event so it should update the game info?
-
Jan 17th, 2012, 01:18 PM
#10
Thread Starter
Junior Member
Re: Get different combinations
Forgot to clear collAllGames. Now it works
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|