List of possible combinations for x numbers.

Discussion in 'Questions (Windows Mobile)' started by EdQas, Oct 6, 2007.

  1. EdQas

    EdQas Member Licensed User

    Hi everybody,
    If I have 3 numbers, the list of all combinations is :
    3*2*1 = 6 possibilities :
    123 132 213 231 312 321

    If I have 7 numbers, there are 5040 possibilities (7*6*5*4*3*2*1).

    :sign0085: : how can i list all of these possibilities ?

    Thank you for the help.

    Ed
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Do you mean something like:
    Code:
    Sub App_Start
        
    Msgbox(Factorial(7))
    End Sub

    Sub Factorial(n)
        f = 
    1
        
    For i = 2 To n
            f = f * i
        
    Next
        
    Return f
    End Sub
     
  3. specci48

    specci48 Well-Known Member Licensed User

    I think he is looking for something like this:

    Code:
    Sub Globals
    End Sub

    Sub App_Start
        
    ' Create a Form1 and add a ListBox1
        FillListBox("1234567""")
        Form1.Show
        
    Msgbox(ListBox1.Count)   
    End Sub

    Sub FillListBox(value, combi)
        
    If value = "" Then
            ListBox1.Add(combi)
        
    Else
            
    For i = 0 To StrLength(value) - 1
                FillListBox(StrRemove(value, i, 
    1), combi & SubString(value, i ,1))      
            
    Next
        
    End If
    End Sub

    specci48
     
  4. EdQas

    EdQas Member Licensed User

    Hurra !

    Thank your Erel and Specci !
    The example of Specci was what i was searching for. :sign0060:
    Once more, many thanks.
    Have a nice sunday.
    Ed
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice