Possible combinations of 5 numbers from 1 to 50

Solved
PrivatD -  
 PrivatD -

Hello,

I would like to test an idea that has been on my mind for some time.

It's about the Euromillions, as you may have guessed.

I would like help to list in Excel all the possible combinations of 5 numbers from 1 to 50.

Any help would be appreciated.

5 answers

  1. Pierr10 Posted messages 13860 Registration date   Status Moderator Last intervention   5 856
     

    Hello,

    It is indeed a combination in the mathematical sense of the term.
    The number of these combinations is (50*49*48*47*46)/(5*4*3*2), which gives:
    2,118,760 possible combinations.

    You're going to need a lot of rows in your Excel spreadsheet!


    What is well conceived is clearly stated,
    And the words to express it come easily.
    (Boileau)
    1
  2. Anonymous user
     

    Hello,

    First of all, I want to draw your attention to Excel's limitations. So you will not be able to do it on a single column. Next, a bit of reading


    When I was little, the Dead Sea was just sick.
    George Burns

    1
    1. PrivatD
       

      Thank you for the reply

      0
  3. mamiemando Posted messages 33174 Registration date   Status Moderator Last intervention   7 944
     

    Hello,

    The question that everyone can naturally ask is what is the point of listing all the combinations. For example, if the goal is to store all the combinations that have already occurred, it is unnecessary to enumerate them all; only those that have occurred are relevant.

    Indeed, from a mathematical perspective, just because a combination has already been made doesn't mean it has more or less chance of occurring in the future. We are talking about independent draws. In other words, maintaining such statistics has no real practical interest.

    Enumeration

    If you still want to enumerate all these combinations, as pointed out by the many people who have already intervened, Excel is quite ill-suited to handle such volumes of data. A language like Python would be much more practical, as shown in the example below.

    from itertools import combinations from pprint import pprint k = 5 # Length of combinations n = 50 # Maximum value of the numbers involved in the combinations c = list(combinations(list(range(1, n + 1)), k)) print(len(c)) # Displays the number of combinations pprint(c[:10]) # Displays the first 10 combinations

    Result:

     2118760 [(1, 2, 3, 4, 5), (1, 2, 3, 4, 6), (1, 2, 3, 4, 7), (1, 2, 3, 4, 8), (1, 2, 3, 4, 9), (1, 2, 3, 4, 10), (1, 2, 3, 4, 11), (1, 2, 3, 4, 12), (1, 2, 3, 4, 13), (1, 2, 3, 4, 14)]

    Counting

    In the case of EuroMillions, the draw is made without replacement, so we are only interested in combinations without repetitions, the number of which is obtained by this formula (see here):

     K(n, k) = n! / (k! * (n - k)!)

    with:

    • ! is the factorial operator;
    • n = 50 (since we have the choice among 50 distinct numbers);
    • k = 5 (since each combination is made up of 5 numbers)

    ... which gives the same result as what Pierr10 calculated in message #1.

    In Python:

    from math import factorial def nc(n, k): return factorial(n) // (factorial(k) * factorial(n - k)) print(nc(50, 5)) # Displays 2118760

    ... or more simply:

    from math import comb print(comb(50, 5))

    Good luck

    1
    1. PrivatD
       

      Thank you

      0
  4. PrivatD
     

    Indeed yes. But now how to list this! Such is the question!

    0
  5. brucine Posted messages 25279 Registration date   Status Member Last intervention   4 186
     

    Hello,

    The question is absolutely pointless, as Pierr10 points out, trying to generate and display this list will crash Excel and the PC, as it won't be easily consulted or serve as a database easily exploitable for numeric processing due to its size.

    It would be more "naturally" handled by a programming language, but only when the expected result is small (which, in terms of factorials, remains quite theoretical). For instance, it's handled here in Python or here in other languages.

    If you're really set on using Excel, nothing is more essential than what is useless. There are different approaches in VBA like here or without it like there.

    0
    1. yg_be Posted messages 23437 Registration date   Status Contributor Last intervention   1 588
       

      Hello, since we need to find 5 numbers, it seems much simpler and faster to work with 5 nested loops.

       Option Explicit Private Sub cc() Dim i1 As Integer, i2 As Integer, i3 As Integer, i4 As Integer, i5 As Integer Dim c As Long, n As Integer Dim r As Long, col As Integer c = 0 n = 50 r = 2 col = 1 Debug.Print Now, n For i1 = 1 To n For i2 = i1 + 1 To n For i3 = i2 + 1 To n For i4 = i3 + 1 To n For i5 = i4 + 1 To n c = c + 1 Cells(r, col) = i1 Cells(r, col + 1) = i2 Cells(r, col + 2) = i3 Cells(r, col + 3) = i4 Cells(r, col + 4) = i5 col = col + 6 If col = 25 Then col = 1 r = r + 1 End If Next i5 Next i4 Next i3 Next i2 Next i1 Debug.Print Now, c End Sub 
      1
      1. jordane45 Posted messages 30427 Registration date   Status Moderator Last intervention   4 833 > yg_be Posted messages 23437 Registration date   Status Contributor Last intervention  
         

        Hello, we need to think about finding combinations without duplicates. And without re-entry. For example: 1,2,3,4,5 is the same as 5,3,4,2,1.

        2
      2. yg_be Posted messages 23437 Registration date   Status Contributor Last intervention   1 588 > jordane45 Posted messages 30427 Registration date   Status Moderator Last intervention  
         

        Yes, thankfully, we are not required to use constants as loop bounds.

        0
      3. PrivatD > yg_be Posted messages 23437 Registration date   Status Contributor Last intervention  
         

        Thank you, I take note

        1