Here you will find daily news and tutorials about R, contributed by over 750 bloggers.
There are many ways to follow us - By e-mail:On Facebook: If you are an R blogger yourself you are invited to add your own R content feed to this site (Non-English R bloggers should add themselves- here)

Abigail and Corentin are both given a positive integer, a and b, such that a+b is either 19 or 20. They are asked one after the other and repeatedly if they are sure of the other’s number. What is the maximum number of times they are questioned?

If Abigail is given a 19, b=1 necessarily. Hence if Abigail does not reply, a<19. This implies that, if Corentin is given b=1 or b=19, he can reply a+b=19 or a+b=20, necessarily. Else, 1

az=bz=cbind(20-(1:19),19-(1:19))
qwz=0;at=TRUE;bt=FALSE
while ((max(az)>0)&(max(bz)>0)){
if (at){
for (i in 1:19){
if (sum(az[i,]>0)==2){
for (j in az[i,az[i,]>0]){
if (sum(bz[j,]==0)==2) az[i,]=rep(0,2)}}
if (sum(az[i,]>0)<2){
az[i,]=rep(0,2)}}}
if (bt){
for (i in 1:19){
if (sum(bz[i,bz[i,]>0]>0)==2){
for (j in bz[i,bz[i,]>0]){
if (sum(az[j,]==0)==2) bz[i,]=rep(0,2)}}
if (sum(bz[i,]>0)<2){ bz[i,]=rep(0,2)}}}
bt=!bt;at=!at;qwz=qwz+1}

Related

To leave a comment for the author, please follow the link and comment on their blog: R – Xi'an's Og.