library(MASS)
rm(list = ls())
options(warn=-1)
set.seed(1234)
Nrep <- 1e04
maxT <- 1e04
As <- rep(0, Nrep)
TAs <- rep(0, Nrep)
Bs <- rep(0, Nrep)
TBs <- rep(0, Nrep)
for (n in 1:Nrep) {
A <- 100
B <- 100
TA <- maxT
TB <- maxT
for (T in 1:maxT) {
Aold <- A
Bold <- B
if (A > 0) A <- A + sample(c(-1, 1), 1, prob = c(49, 51))
if (B > 0) B <- B + sample(c(-1, 1), 1, prob = c(51, 49))
if (A == 0 & Aold > 0) TA <- T
if (B == 0 & Bold > 0) TB <- T
}
TAs[n] <- TA
As[n] <- A
TBs[n] <- TB
Bs[n] <- B
}
NAbusts <- sum(As == 0)
NAbusts
## [1] 134
if (NAbusts > 0) truehist(TAs[As == 0], prob = FALSE)

NBbusts <- sum(Bs == 0)
NBbusts
## [1] 9158
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] 122
sum(TAs > TBs & As == 0 & Bs == 0)/sum(As == 0 & Bs == 0) # Bob bust before Alice given both went bust
## [1] 0.4672131
sum(TAs < TBs & As == 0 & Bs == 0)/sum(As == 0 & Bs == 0) # Alice bust before Bob given both went bust
## [1] 0.5327869