another drawer of socks
This article is originally published at https://xianblog.wordpress.com
A socks riddle from the Riddler but with no clear ABC connection! Twenty-eight socks from fourteen pairs of socks are taken from a drawer, one by one, and laid on a surface that only fit nine socks at a time, with complete pairs removed. What is the probability that all pairs are stored without running out of space? No orphan socks then!!
Writing an R code for this experiment is straightforward
for(v in 1:1e6){ S=sample(rep(1:14,2)) x=S[1] for(t in 2:18){ if(S[t]%in%x){x=x[S[t]!=x]}else{x=c(x,S[t])} if(sum(!!x)>9){ F=F+1;break()}}}
and it returns a value quite close to 0.7 for the probability of success. I was expecting a less brute-force resolution but the the Riddler only provided the answer of 70.049 based on the above tree of probabilities (which I was too lazy to code).
Thanks for visiting r-craft.org
This article is originally published at https://xianblog.wordpress.com
Please visit source website for post related comments.