Consulting

Results 1 to 3 of 3

Thread: probability of getting a pair in poker in excel

  1. #1
    VBAX Newbie
    Joined
    Jul 2024
    Posts
    4
    Location

    probability of getting a pair in poker in excel

    I'm working on a probability problem related to poker, and I could really use some help with figuring out how to calculate it in Excel. Here’s the scenario:


    In a game of poker, you're dealt 5 cards from a standard deck of 52 cards. I want to determine the probability of getting at least one pair (i.e., two cards of the same rank) in my hand.


    I understand that this involves some combinatorial calculations, but I'm not sure how to set it up properly in Excel. I've been playing poker online and this question came up because I'm interested in evaluating my chances of winning. Could someone help me verify if this approach is correct and guide me on how to properly set up these calculations in Excel?
    Last edited by georgiboy; 07-03-2024 at 10:08 AM. Reason: Removed spam link

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,851
    Location
    Capture.JPG
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,449
    Location
    Kind of bored tonight so.... is this a different version?

    ' Function to calculate combinations (nCr)
    Function Combinations(n As Integer, r As Integer) As Double
        ' Handle cases where r is invalid
        If r < 0 Or r > n Then
            Combinations = 0
            ' Handle base cases for combinations
        ElseIf 
            r = 0 Or r = n Then
            Combinations = 1
            ' Optimize calculation by choosing the smaller 'r'
        ElseIf 
            r > n / 2 Then
            Combinations = Combinations(n, n - r)
            ' Calculate the combination iteratively
        Else
            Dim result As Double
            result = 1
            For i = 1 To r
                result = result * (n - i + 1) / i
            Next i
            Combinations = result
        End If
    End Function
    
    Sub CalculatePairProbability()
        ' Declare variables to store the calculated values
        Dim totalPossibleHands As Double
        Dim handsWithNoPair As Double
        Dim probabilityOfNoPair As Double
        Dim probabilityOfAtLeastOnePair As Double
        ' 1. Calculate the total number of possible 5-card hands
        totalPossibleHands = Combinations(52, 5)
        ' 2. Calculate the number of 5-card hands with NO pairs
        '    a) Choose 5 distinct ranks from 13 available ranks
        Dim numberOfRankCombinations As Double
        numberOfRankCombinations = Combinations(13, 5)
        '    b) For each of these 5 ranks, choose 1 of the 4 suits
        Dim numberOfSuitCombinations As Double
        numberOfSuitCombinations = 4 ^ 5 ' 4 choices for each of the 5 cards  
        '    c) Total number of "no pair" hands
        handsWithNoPair = numberOfRankCombinations * numberOfSuitCombinations
        ' 3. Calculate the probability of getting NO pairs
        probabilityOfNoPair = handsWithNoPair / totalPossibleHands
        ' 4. Calculate the probability of getting AT LEAST ONE pair
        '    This is 1 minus the probability of getting no pairs
        probabilityOfAtLeastOnePair = 1 - probabilityOfNoPair
        ' Display the result to the user
        MsgBox "The probability of getting at least one pair in a 5-card hand is approximately: " & Format(probabilityOfAtLeastOnePair, "0.00%")
    End Sub' 
    
    ' --- End of Module Level Code ---
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •