# triple ruin

**R – Xi'an's Og**, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The Riddler involving a triple gambler’s ruin: *Dawn competes against three players Alessandra, Berenike, and Chinue, with probabilities of winning one round ¾, ½, and ¼, respectively, until the cumulated score reaches ±15, ±30, and ±45, for the first, second, and third games. What is Dawn’s optimal sequence of adversaries?*

First, a brute force R simulation shows that the optimal ordering is to play the three adversaries first weakest, third strongest and middle fair:

ord=function(p){ z=2*(runif(1)<p[1])-1 while(abs(z)<15)z=z+2*(runif(1)<p[1])-1 y=2*(runif(1)<p[2])-1 while(abs(z+y)<30)y=y+2*(runif(1)<p[2])-1 x=2*(runif(1)<p[3])-1 while(abs(z+y+x)<45)x=x+2*(runif(1)<p[3])-1 return(x+y+z>0)} mcord=function(p,T=1e2){ for(t in 1:T)F=F+ord(p) return(F/T)} comp=function(T=1e2){ return(c(mcord(c(.5,.55,.45),t), #mcord(c(.5,.45,.55),t),#1-above mcord(c(.55,.5,.45),t), #mcord(c(.45,.5,.55),t),#1-above mcord(c(.55,.45,.5),t) #mcord(c(.45,.55,.5),t)))#1-above ))}

where I used probabilities closer to *½* to avoid estimated probabilities equal to one.

> comp(1e3) [1] 0.051 0.038 0.183

(and I eliminated the three other probabilities by sheer symmetry). Second, checking in Feller’s bible (Vol. 1, XIV.3) for the gambler’s ruin probability, a simple comparison of the six orderings confirms this simulation.

**leave a comment**for the author, please follow the link and comment on their blog:

**R – Xi'an's Og**.

R-bloggers.com offers

**daily e-mail updates**about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.