TITLE: Probability of Bride entering the Church?
QUESTION [9 upvotes]: A Bride is standing at the entrance of a church with her father (one step forward will take her into the church). Her father has a basket containing $10$ White roses and $10$ Red roses. He takes $1$ rose at a time from the basket and gives it to the Bride. If the rose is Red, the Bride takes $1$ step towards the church and if it is White, she takes $1$ step away from the church. What is the probability that the Bride enters the church? Assume that Bride's father can not see the rose until he takes the rose out of the basket.
I am stuck at this point: If the first rose is Red then the Bride enters the Church and in that case the probability is $\frac{10}{20}$. But then come the cases when the first rose is White: WRR, WWRRR, WRWRR and so on. No matter what, if the first rose is White, the last two roses must be Red. And the total number of roses required (⩽20) to enter the church is Odd, where the number of Red roses will never exceed that of the White roses but once when the Bride finally enters the church. Leaves me in doldrums, though

REPLY [3 votes]: As per suggestion by @pm-2ring I'm posting my comment from above as an answer.
I'd like to share a solution in C++ because I found the problem quite interesting. 

The program starts with the string "00000000001111111111" and goes through all lexicographic permutations by using Pandita's algorithm. 
For each permutation it goes through the string and checks if the number of ones exceeds the number of zeros. You can click on 'edit' to change the string and check the other cases, e.g. set the string to "000111" to check the case with 3 red roses and 3 white roses.

I also implemented a solution in Python. As mentioned by @pm-2ring there is no built-in function that returns the next lexicographic permutation in Python, so I had to implement Pandita's algorithm.
Edit:
- Added sourcecode in C++, Python and C
The program's output for 10 red and 10 white roses is:
number of times bride entered church: 167960
total permutations: 184756
probability: 0.909091


Code in C++:
#include <bits/stdc++.h>
using namespace std;


int main() {
    string s = "00000000001111111111";            // red and white roses 
    sort(s.begin(), s.end());

    int total_permutations = 0;
    int count_in_church = 0;


    // check next lexicographic permutation of s 
    do {
        total_permutations += 1;

        // check if bride steps into church by checking if
        // the number of ones exceeds the number of zeros
        int cnt_0 = 0;
        int cnt_1 = 0;

        for (char c : s) {
            if (c == '0') {cnt_0 += 1;}
            else {cnt_1 += 1;}

            if (cnt_1 > cnt_0) {
                count_in_church += 1;
                break;
            }
        }

    } while(std::next_permutation(s.begin(), s.end()));


    cout << "number of times bride entered church: " << count_in_church << '\n';
    cout << "total permutations: " << total_permutations << '\n';
    cout << "probability: " << 1.0 * count_in_church / total_permutations << '\n';
}


Code in Python:
def next_permutation(L):
    '''
    Permute the list L in-place to generate the next lexicographic permutation.
    Return True if such a permutation exists, else return False.
    '''

    n = len(L)

    #------------------------------------------------------------

    # Step 1: find rightmost position i such that L[i] < L[i+1]
    i = n - 2
    while i >= 0 and L[i] >= L[i+1]:
        i -= 1

    if i == -1:
        return False

    #------------------------------------------------------------

    # Step 2: find rightmost position j to the right of i such that L[j] > L[i]
    j = i + 1
    while j < n and L[j] > L[i]:
        j += 1
    j -= 1

    #------------------------------------------------------------

    # Step 3: swap L[i] and L[j]
    L[i], L[j] = L[j], L[i]

    #------------------------------------------------------------

    # Step 4: reverse everything to the right of i
    left = i + 1
    right = n - 1

    while left < right:
        L[left], L[right] = L[right], L[left]
        left += 1
        right -= 1

    return True



#-------------------------------------------------------------------
#-------------------------------------------------------------------

def example():
    count_in_church = 0
    total_permutations = 0
    k = 10
    L = k*[0] + k*[1]

    while True:
        total_permutations += 1

        # check if bride steps into church by checking if
        # the number of ones exceeds the number of zeros
        cnt_0 = 0
        cnt_1 = 0

        for c in L:
            if c == 0: cnt_0 += 1
            else: cnt_1 += 1

            if cnt_1 > cnt_0:
                count_in_church += 1
                break

        if not next_permutation(L):
            break

    print("number of times bride entered church: ", count_in_church)
    print("total permutations:", total_permutations)
    print("probability:", count_in_church / total_permutations)


#----------------------------------------------------------------

if __name__ == "__main__":
    example()


Code in C:
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

//-----------------------------------------------------------------

// Pandita's algorithm to generate next lexicographic permutation

bool next_permutation(char *L, int n) {
  // Step 1: find rightmost position i such that L[i] < L[i+1]
  int i = n - 2;
  while ((i >= 0) && (L[i] >= L[i+1])) i--;
  if (i==-1) return false;

  // Step 2: find rightmost position j to the right of i such that L[j] > L[i]
  int j = i + 1;
  while ((j < n) & (L[j] > L[i])) j += 1;
  j -= 1;

  // Step 3: swap L[i] and L[j]
  char tmp = L[i];
  L[i] = L[j];
  L[j] = tmp;

  // Step 5: reverse everything to the right of i
  int left = i + 1;
  int right = n - 1;

  while (left < right) {
    tmp = L[left];
    L[left] = L[right];
    L[right] = tmp;
    left += 1;
    right -= 1;
  }

  return true;
}


//-----------------------------------------------------------------

int main(){
  char L[] = "00000000001111111111";
  int n = strlen(L);

  int count_in_church = 0;
  int total_permutations = 0;

  while (1) {

    total_permutations += 1;
    // check if bride steps into church by checking if
    // the number of ones exceeds the number of zeros
    int cnt_0 = 0;
    int cnt_1 = 0;


    for (int i=0; i<n; i++) {
      char c = L[i];
      if (c == '0') cnt_0 += 1;
      else cnt_1 += 1;

      if (cnt_1 > cnt_0) {
        count_in_church += 1;
        break;
      }
    }


    if (!next_permutation(L,n)) break;
  }


  printf("number of times bride entered church: %d\n", count_in_church);
  printf("total permutations: %d\n", total_permutations);

  float ratio = 1.0 * count_in_church / total_permutations;
  printf("probability: %f\n", ratio);

    return 0;
}