Results 1 to 4 of 4

Thread: 3 numbers on 9 (vb net)

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2006
    Posts
    3

    3 numbers on 9 (vb net)

    Hello

    i have a ist of 9 numbers
    i need them grouped by 3, but only one time : 123 but not 213, 321, 231,...

    the list >> 1,2,3,4,5,6,7,8,9

    I must get (in any collection) >>
    123
    124
    125
    126
    129
    ...
    234
    245
    ...


    thank you for helping

  2. #2
    Junior Member
    Join Date
    Aug 2006
    Posts
    16

    Re: 3 numbers on 9 (vb net)

    Erm... what exactly are you asking for? An algorithm to do this? How many groups you will have?

    If you want the total number of groups where order doesn't matter (so {1,2,3} is the same as {2,1,3}) then:

    There are 9*8*7 groups with different orders accounted for - ignoring order, each group appears 3*2*1 times. Thus the number of groups you'll end up having is

    9*8*7/3*2*1 = 84 distinct groups.

    An algorithm shouldn't be too hard to make up.

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2006
    Posts
    3

    Re: 3 numbers on 9 (vb net)

    i was there

    Private Sub TroisDeNeuf()
    Dim neufa As New StringCollection
    Dim neufb As New StringCollection
    Dim neufc As New StringCollection
    For a As Integer = 1 To 9
    neufa.Add(a.tostring)
    Next
    neufb = neufa
    neufc = neufa
    Dim sb As New StringBuilder
    Dim i As Integer = 0

    For a As Integer = 0 To 8
    For b As Integer = 0 To 8
    For c As Integer = 0 To 8
    If a <> b AndAlso a <> c AndAlso b <> c Then
    sb.AppendFormat("{0} {1} {2}<br />", neufa(a), neufa(b), neufa(c))
    i += 1
    End If
    Next
    Next
    'here i must remove i=+1
    Next
    Me.AddLiteral(i.ToString & "<hr />")
    Me.AddLiteral(sb.ToString)
    End Sub

    i must not get 113 or 445 , each number must be different, and of course if i have allready 234, i cannot have 243

    the numbers are not 1to 9 of course but i have an array with 9 numbers
    like 14,7,45,102,58,66,24,87,55

  4. #4

    Thread Starter
    New Member
    Join Date
    Sep 2006
    Posts
    3

    Re: 3 numbers on 9 (vb net)

    it works :

    Dim neufa As New StringCollection
    For X As Integer = 1 To 9
    neufa.Add(X.ToString)
    Next
    Dim a, b, c As Integer

    Dim sb As New StringBuilder
    Dim i As Integer = 0

    For a = 0 to 6
    For b = a + 1 to 7
    For c = b + 1 to 8
    sb.AppendFormat("{0} {1} {2} <br />", neufa(a), neufa(b), neufa(c))
    Next
    Next
    Next

    Me.AddLiteral(i.ToString & "<hr />")
    Me.AddLiteral(sb.ToString)
    Last edited by anselmej; Sep 24th, 2006 at 11:19 AM.

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