Results 1 to 10 of 10

Thread: Get different combinations

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2012
    Posts
    30

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

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    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

  3. #3
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Get different combinations

    Quote Originally Posted by stevefox View Post
    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.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jan 2012
    Posts
    30

    Re: Get different combinations

    Quote Originally Posted by jcis View Post
    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?

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jan 2012
    Posts
    30

    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.

  6. #6
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    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.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Jan 2012
    Posts
    30

    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.

  8. #8
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Get different combinations

    Quote Originally Posted by stevefox View Post
    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
    '...
    Quote Originally Posted by stevefox View Post
    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?

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Jan 2012
    Posts
    30

    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?

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Jan 2012
    Posts
    30

    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
  •  



Click Here to Expand Forum to Full Width