See the top rated post in this thread. Click here

Results 1 to 13 of 115

Thread: New deck at cut

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1


    Did you find this post helpful? Yes | No
    Quote Originally Posted by Cacarulo View Post
    I apologize, I may have formulated the problem incorrectly. What I meant to ask is:
    What is the probability of getting 2 or more consecutive heads in 4 tosses of a fair coin (p = 0.5)?
    I'm just trying to see what value the iCNT code returns.

    Sincerely,
    Cac
    So my code returns 0.0625 which is blatantly incorrect as the correct number is 0.3125 if we do exactly 2 consecutive heads or 0.5 if we do 2 or more consecutive heads (3 or 4 in this case). My code is an adaptation of de Moivre formula which works fairly well when the number of trials increases but fails for small number of trials.

    I have of course looked at brute force combinatorial analysis but while the code is fairly simple, the calculation quickly becomes intractable as the number of trials increases because for n trials you have 2^n possible permutations, so you can kiss solving 7000 rounds (2^7000) good bye .

    I was able to implement a fairly easy sim that reproduces the values. Below is the implementation in VBA if you want to test it in Excel. @Norm please dont hate me for using the built-in RNG

    Code:
    
    Sub TestMe()
        Debug.Print ProbabilityOfStreak(2, 0.5, 4, 100000, True)
    End Sub
    
    Function ProbabilityOfStreak(l As Long, p As Double, n As Long, simulations As Long, allowLonger As Boolean) As Double
        Dim streakCount As Long
        Dim currentStreak As Long
        Dim i As Long
        Dim j As Long
        Dim successfulSimulations As Long
        
        successfulSimulations = 0
        
        ' Seed the random number generator
        Randomize
        
        ' Randomly generate each trial and count the number of successful simulations with exactly one streak of length l
        For i = 1 To simulations
            currentStreak = 0
            streakCount = 0
            For j = 1 To n
                If Rnd() < p Then
                    ' Increment streak if the event occurs
                    currentStreak = currentStreak + 1
                Else
                    ' Check if the streak ended and was exactly length l or longer based on allowLonger flag
                    If (allowLonger And currentStreak >= l) Or (Not allowLonger And currentStreak = l) Then
                        streakCount = streakCount + 1
                    End If
                    currentStreak = 0
                End If
            Next j
            ' Check streak at the end of the trials
            If (allowLonger And currentStreak >= l) Or (Not allowLonger And currentStreak = l) Then
                streakCount = streakCount + 1
            End If
            
            ' Check if exactly one streak of length l occurred
            If streakCount = 1 Then
                successfulSimulations = successfulSimulations + 1
            End If
        Next i
        
        ' Calculate probability based on sim results
        ProbabilityOfStreak = successfulSimulations / simulations
    End Function
    Chance favors the prepared mind

  2. #2


    Did you find this post helpful? Yes | No
    Quote Originally Posted by iCountNTrack View Post
    So my code returns 0.0625 which is blatantly incorrect as the correct number is 0.3125 if we do exactly 2 consecutive heads or 0.5 if we do 2 or more consecutive heads (3 or 4 in this case). My code is an adaptation of de Moivre formula which works fairly well when the number of trials increases but fails for small number of trials.

    I have of course looked at brute force combinatorial analysis but while the code is fairly simple, the calculation quickly becomes intractable as the number of trials increases because for n trials you have 2^n possible permutations, so you can kiss solving 7000 rounds (2^7000) good bye .

    I was able to implement a fairly easy sim that reproduces the values. Below is the implementation in VBA if you want to test it in Excel. @Norm please dont hate me for using the built-in RNG

    Code:
    
    Sub TestMe()
        Debug.Print ProbabilityOfStreak(2, 0.5, 4, 100000, True)
    End Sub
    
    Function ProbabilityOfStreak(l As Long, p As Double, n As Long, simulations As Long, allowLonger As Boolean) As Double
        Dim streakCount As Long
        Dim currentStreak As Long
        Dim i As Long
        Dim j As Long
        Dim successfulSimulations As Long
        
        successfulSimulations = 0
        
        ' Seed the random number generator
        Randomize
        
        ' Randomly generate each trial and count the number of successful simulations with exactly one streak of length l
        For i = 1 To simulations
            currentStreak = 0
            streakCount = 0
            For j = 1 To n
                If Rnd() < p Then
                    ' Increment streak if the event occurs
                    currentStreak = currentStreak + 1
                Else
                    ' Check if the streak ended and was exactly length l or longer based on allowLonger flag
                    If (allowLonger And currentStreak >= l) Or (Not allowLonger And currentStreak = l) Then
                        streakCount = streakCount + 1
                    End If
                    currentStreak = 0
                End If
            Next j
            ' Check streak at the end of the trials
            If (allowLonger And currentStreak >= l) Or (Not allowLonger And currentStreak = l) Then
                streakCount = streakCount + 1
            End If
            
            ' Check if exactly one streak of length l occurred
            If streakCount = 1 Then
                successfulSimulations = successfulSimulations + 1
            End If
        Next i
        
        ' Calculate probability based on sim results
        ProbabilityOfStreak = successfulSimulations / simulations
    End Function
    Exactly, that's why using combinatorial analysis is not advisable in this type of problems. Not to mention the use of factorials.
    A long simulation is much more reliable. Let me give you an example of why combinatorial analysis fails.
    Suppose we want to calculate C (1000, 30). The following are 3 values obtained by different routines:
    The first one corresponds to the code you posted above (binomialCoefficient).
    The next two correspond to two routines of mine.
    The correct one is none of the 3.

    BC1 = 6427395792647100880
    BC2 = 2429608192173745103000302810053683821765033166213128126464
    BC3 = 2429608192173745103170443993514153053496720469929012232192


    Here is the correct value:

    BC4 = 24296081921737451032703898385767507193022226061986 31438800

    Your 0.0625 is correct for 4 consecutive heads in 4 tosses. There might be a bug somewhere. Maybe by fixing that, the program will work for these simpler cases.

    Sincerely,
    Cac
    Luck is what happens when preparation meets opportunity.

Similar Threads

  1. Don, would you suggest to round down deck estimation in single deck?
    By San Jose Bella in forum General Blackjack Forum
    Replies: 61
    Last Post: 07-12-2022, 03:38 PM
  2. Does Reko work best in single deck or 6 deck or doesn't matter.
    By San Jose Bella in forum General Blackjack Forum
    Replies: 12
    Last Post: 03-14-2018, 01:52 AM
  3. Reko f six deck eight deck exit table strategy
    By monster754rehab in forum General Blackjack Forum
    Replies: 3
    Last Post: 04-06-2016, 08:55 AM
  4. Best count system for 2 deck, 4 deck, 6 deck, 8 deck?
    By DickFer in forum General Blackjack Forum
    Replies: 31
    Last Post: 06-24-2015, 09:56 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

About Blackjack: The Forum

BJTF is an advantage player site based on the principles of comity. That is, civil and considerate behavior for the mutual benefit of all involved. The goal of advantage play is the legal extraction of funds from gaming establishments by gaining a mathematic advantage and developing the skills required to use that advantage. To maximize our success, it is important to understand that we are all on the same side. Personal conflicts simply get in the way of our goals.