Welcome Guest
Log In | Register )
You last visited December 10, 2016, 1:24 pm
All times shown are
Eastern Time (GMT-5:00)

unique comb of 0123456789

Topic closed. 9 replies. Last post 5 years ago by phileight.

Page 1 of 1
PrintE-mailLink
Avatar

United States
Member #41846
June 23, 2006
460 Posts
Offline
Posted: December 15, 2011, 11:06 am - IP Logged

My brain seems to have taken a vacation. using all 10 digits, any digit can be in any position but can only be used once per combination. how many unique combinations are there?  do you have program code to generate these unique combinations?

 

p8

    RJOh's avatar - chipmunk
    mid-Ohio
    United States
    Member #9
    March 24, 2001
    19831 Posts
    Offline
    Posted: December 15, 2011, 2:42 pm - IP Logged

    If you're talking about Pick3 and Pick4 games then Maybelle QuickWheel can tell you that when it prints out all the possible combinations without triples or doubles.  You can download it from Lotto Logix.

     * you don't need to buy more tickets, just buy a winning ticket * 
       
                 Evil Looking       

      Avatar
      bgonçalves
      Brasil
      Member #92564
      June 9, 2010
      2126 Posts
      Offline
      Posted: December 15, 2011, 3:32 pm - IP Logged

      Hello, PHI, this type of matrix, until I got the six digit

      1 2 3 4 5 6

      2 3 1 6 4 5

      3 1 2 5 6 4

      4 6 5 1 2 3

      5 4 6 2 3 1

      6 5 4 3 1 2

        Avatar

        United States
        Member #41846
        June 23, 2006
        460 Posts
        Offline
        Posted: December 15, 2011, 6:43 pm - IP Logged

        thanks RJOH and DR San.  this is not for a wheel type application.

        what i want to do is

        0123456789

        0123456798

        0123456879

        0123456897  etc

        I have always assumed that there were too many combinations and just created random strings of these digits. doing that I can never say i have the absolute best arrangement. I think there are around 150000 possible combinations, but I'm not sure.   can't seem to put 2 lines of code together today.

        p8

          garyo1954's avatar - garyo
          Dallas, Texas
          United States
          Member #4549
          May 2, 2004
          1736 Posts
          Offline
          Posted: December 15, 2011, 6:48 pm - IP Logged

          thanks RJOH and DR San.  this is not for a wheel type application.

          what i want to do is

          0123456789

          0123456798

          0123456879

          0123456897  etc

          I have always assumed that there were too many combinations and just created random strings of these digits. doing that I can never say i have the absolute best arrangement. I think there are around 150000 possible combinations, but I'm not sure.   can't seem to put 2 lines of code together today.

          p8

          Using all ten digits in each combination?

          Want it in QBASIC64?

          Take maybe 20 minutes tops.

          Can you run it?

            garyo1954's avatar - garyo
            Dallas, Texas
            United States
            Member #4549
            May 2, 2004
            1736 Posts
            Offline
            Posted: December 15, 2011, 7:31 pm - IP Logged

            Using nonrepeating digits........

            Using 1 digits: 10  combinations

            Using 2 digits: 10*9 = 90 combinations

            Using 3 digits: 10*9*8 = 720  combinations

            Using 4 digits: 10*9*8*7 = 5040 combinations

            Using 5 digits: 10*9*8*7*6 = 30240 combinations

            Using 6 digits: 10*9*8*7*6*5 = 151200 combinations

            Using 7 digits: 10*9*8*7*6*5*4 = 604800 combinations

            Using 8 digits: 10*9*8*7*6*5*4*3 = 1814400 combinations

            Using 9 digits: 10*9*8*7*6*5*4*3*2 = 3628800 combinations

            Using 10 digits: 10*9*8*7*6*5*4*3*2*1 = 3628800 combinations

              Avatar

              United States
              Member #41846
              June 23, 2006
              460 Posts
              Offline
              Posted: December 16, 2011, 6:14 am - IP Logged

              Using nonrepeating digits........

              Using 1 digits: 10  combinations

              Using 2 digits: 10*9 = 90 combinations

              Using 3 digits: 10*9*8 = 720  combinations

              Using 4 digits: 10*9*8*7 = 5040 combinations

              Using 5 digits: 10*9*8*7*6 = 30240 combinations

              Using 6 digits: 10*9*8*7*6*5 = 151200 combinations

              Using 7 digits: 10*9*8*7*6*5*4 = 604800 combinations

              Using 8 digits: 10*9*8*7*6*5*4*3 = 1814400 combinations

              Using 9 digits: 10*9*8*7*6*5*4*3*2 = 3628800 combinations

              Using 10 digits: 10*9*8*7*6*5*4*3*2*1 = 3628800 combinations

              Garyo1954

              I have never used qbasic64.  i have used most other versions of basic.  would appreciate the code. with a couple changes it should work in VBA .  there are more comb than I expected but still workable I think.

                garyo1954's avatar - garyo
                Dallas, Texas
                United States
                Member #4549
                May 2, 2004
                1736 Posts
                Offline
                Posted: December 16, 2011, 10:51 am - IP Logged

                Didn't bother working on it when you didn't reply.  Used the old fashioned method.

                Post what you have. There are plenty of people who can help.

                  CARBOB's avatar - FL LOTTERY_LOGO.png
                  ORLANDO, FLORIDA
                  United States
                  Member #4924
                  June 3, 2004
                  5912 Posts
                  Offline
                  Posted: December 16, 2011, 12:22 pm - IP Logged

                  phileight,

                  The code below was written for Excel 03. Needs to be updated to allow for the extra rows & columns in  Excel 07. Unfortunately, I'm not a VB person. Setup for worksheet

                   

                   

                  Option Explicit

                   


                  ' PGC Set 2007
                  ' Calculates and writes the Combinations / Permutations with/without repetition
                  ' Assumes the result is written from row 1 down. If the total number of cells in a column
                  ' is less than tha number of results continues in another group of columns to the right.
                  ' vElements - Array with the set elements (1 to n)
                  ' p - number of elements in 1 combination/permutation
                  ' bComb - True: Combinations, False: Permutations
                  ' bRepet - True: with repetition, False: without repetition
                  ' vResult - Array to hold 1 permutation/combination (1 to p)
                  ' lRow - row number. the next combination/permutation is written in lRow+1
                  ' vResultAll - Array to hold all the permutations/combinations (1 to Total, 1 to p)
                  ' iElement - order of the element to process in case of combination
                  ' iIndex - position of the next element in the combination/permutation

                  ' Sub CombPerm() deals with the input / output
                  ' Sub CombPermNP() generates the combinations / permutations

                  Sub CombPerm()
                  Dim rRng As Range, p As Integer
                  Dim vElements As Variant, vResult As Variant, vResultAll As Variant, lTotal As Long
                  Dim lRow As Long, bComb As Boolean, bRepet As Boolean
                  Dim vResultPart, iGroup As Integer, l As Long, lMax As Long, k As Long

                  ' Get the inputs and clear the result range (you may adjust for other locations)
                  Set rRng = Range("B5", Range("B5").End(xlDown)) ' The set of numbers
                  p = Range("B1").Value ' How many are picked
                  bComb = Range("B2")
                  bRepet = Range("B3")
                  Range("D1", Cells(1, Columns.Count)).EntireColumn.Clear

                  ' Error
                  If (Not bRepet) And (rRng.Count < p) Then
                      MsgBox "With no repetition the number of elements of the set must be bigger or equal to p"
                      Exit Sub
                  End If

                  ' Set up the arrays for the set elements and the result
                  vElements = Application.Index(Application.Transpose(rRng), 1, 0)
                  With Application.WorksheetFunction
                      If bComb = True Then
                              lTotal = .Combin(rRng.Count + IIf(bRepet, p - 1, 0), p)
                      Else
                          If bRepet = False Then lTotal = .Permut(rRng.Count, p) Else lTotal = rRng.Count ^ p
                      End If
                  End With
                  ReDim vResult(1 To p)
                  ReDim vResultAll(1 To lTotal, 1 To p)

                  ' Calculate the Combinations / Permutations
                  Call CombPermNP(vElements, p, bComb, bRepet, vResult, lRow, vResultAll, 1, 1)

                  ' Write the  Combinations / Permutations
                  ' Since writing to the worksheet cell be cell is very slow, uses temporary arrays to write one column at a time
                  Application.ScreenUpdating = False
                  If lTotal <= Rows.Count Then
                      Range("D1").Resize(lTotal, p).Value = vResultAll
                  Else
                      While iGroup * Rows.Count < lTotal
                          lMax = lTotal - iGroup * Rows.Count
                          If lMax > Rows.Count Then lMax = Rows.Count
                          ReDim vResultPart(1 To lMax, 1 To p)
                          For l = 1 To lMax
                              For k = 1 To p
                                  vResultPart(l, k) = vResultAll(l + iGroup * Rows.Count, k)
                              Next k
                          Next
                          Range("D1").Offset(0, iGroup * (p + 1)).Resize(lMax, p).Value = vResultPart
                          iGroup = iGroup + 1
                      Wend
                  End If
                  Application.ScreenUpdating = True
                  End Sub

                  Sub CombPermNP(ByVal vElements As Variant, ByVal p As Integer, ByVal bComb As Boolean, ByVal bRepet As Boolean, _
                                               ByVal vResult As Variant, ByRef lRow As Long, ByRef vResultAll As Variant, ByVal iElement As Integer, ByVal iIndex As Integer)
                  Dim i As Integer, j As Integer, bSkip As Boolean

                  For i = IIf(bComb, iElement, 1) To UBound(vElements)
                      bSkip = False
                      ' in case of permutation without repetition makes sure the element is not yet used
                      If (Not bComb) And Not bRepet Then
                          For j = 1 To p
                              If vElements(i) = vResult(j) And Not IsEmpty(vResult(j)) Then
                                  bSkip = True
                                  Exit For
                              End If
                          Next
                      End If

                      If Not bSkip Then
                          vResult(iIndex) = vElements(i)
                          If iIndex = p Then
                              lRow = lRow + 1
                              For j = 1 To p
                                  vResultAll(lRow, j) = vResult(j)
                              Next j
                          Else
                              Call CombPermNP(vElements, p, bComb, bRepet, vResult, lRow, vResultAll, i + IIf(bComb And bRepet, 0, 1), iIndex + 1)
                          End If
                      End If
                  Next i
                  End Sub

                    Avatar

                    United States
                    Member #41846
                    June 23, 2006
                    460 Posts
                    Offline
                    Posted: December 16, 2011, 6:10 pm - IP Logged

                    Carbob

                    thanks. i gave it a quick test seems to work ok. I'll get deeper later. curious to see total numer of combinations

                    and how long it takes to run.