library(MASS)
rm(list = ls())
options(warn=-1)
set.seed(1234)
Nrep <- 1e05
maxT <- 1e05
As <- rep(0, Nrep)
TAs <- rep(0, Nrep)
Bs <- rep(0, Nrep)
TBs <- rep(0, Nrep)
for (n in 1:Nrep) {
A <- sample(c(-1, 1), maxT, prob = c(49, 51), replace = TRUE)
B <- sample(c(-1, 1), maxT, prob = c(51, 49), replace = TRUE)
AA <- c(100, 100 + cumsum(A))
BB <- c(100, 100 + cumsum(B))
TA <- min((0:maxT)[AA <= 0], maxT)
TB <- min((0:maxT)[BB <= 0], maxT)
As[n] <- AA[TA + 1]
TAs[n] <- TA
Bs[n] <- BB[TB + 1]
TBs[n] <- TB
}
NAbusts <- sum(As == 0)
NAbusts
## [1] 1782
if (NAbusts > 0) truehist(TAs[As == 0], prob = FALSE)

NBbusts <- sum(Bs == 0)
NBbusts
## [1] 100000
if(NBbusts > 0) truehist(TBs[Bs == 0], prob = FALSE)

if(NAbusts < Nrep) truehist(As[As > 0], prob = FALSE)

if(NBbusts < Nrep) truehist(Bs[Bs > 0], prob = FALSE)
sum(As == 0 & Bs == 0)
## [1] 1782
sum(TAs > TBs & As == 0 & Bs == 0)/sum(As == 0 & Bs == 0) # Bob bust before Alice given both went bust
## [1] 0.5112233
sum(TAs < TBs & As == 0 & Bs == 0)/sum(As == 0 & Bs == 0) # Alice bust before Bob given both went bust
## [1] 0.4887767