**T**he penultimate and appropriately somewhat Monty Hallesque Le Monde mathematical puzzle of the competition!

A dresser with 5×5 drawers contains a single object in one of the 25 drawers. A player opens a drawer at random and, after each choice, the object moves at random to a drawer adjacent to its current location and the drawer chosen by the player remains open. What is the maximum number of drawers one need to open to find the object?

In a dresser with 9 drawers in a line, containing again a single object, the player opens drawers one at a time, after which the open drawer is closed and the object moves to one of the drawers adjacent to its current location. What is the maximum number of drawers one need to open to find the object?

**F**or the first question, setting a pattern of exploration and, given this pattern, simulating a random walk trying to avoid the said pattern as long as possible is feasible, returning a maximum number of steps over many random walks [and hence a lower bound on the true maximum]. As in the following code

sefavyd=function(pater=seq(1,49,2)%%25+1){ fild=matrix(0,5,5) m=pater[1];i=fild[m]=1 t=sample((1:25)[-m],1) nomove=FALSE while (!nomove){ i=i+1 m=pater[i];fild[m]=1 if (t==m){ nomove=TRUE}else{ muv=NULL if ((t-1)%%5>0) muv=c(muv,t-1) if (t%%5>0) muv=c(muv,t+1) if ((t-1)%/%5>0) muv=c(muv,t-5) if (t%/%5<4) muv=c(muv,t+5) muv=muv[fild[muv]==0] nomove=(length(muv)==0) if (!nomove) t=sample(rep(muv,2),1)} } return(i)}

But a direct reasoning starts from the observation that, while two adjacent drawers are not opened, a random walk can, with non-zero probability, switch indefinitely between both drawers. Hence, a sure recovery of the object requires opening one drawer out of two. The minimal number of drawers to open on a 5×5 dresser is 2+3+2+3+2=12. Since in 12 steps, those drawers are all open, spotting the object may require up to 13 steps.

For the second case, unless I [again!] misread the question, whatever pattern one picks for the exploration, there is always a non-zero probability to avoid discovery after an arbitrary number of steps. The [wrong!] answer is thus infinity. To cross-check this reasoning, I wrote the following R code that mimics a random pattern of exploration, associated by an opportunistic random walk that avoids discovery whenever possible (even with very low probability) bu pushing the object towards the centre,

drawl=function(){ i=1;t=5;nomove=FALSE m=sample((1:9)[-t],1) while (!nomove){ nextm=sample((1:9),1) muv=c(t-1,t+1) muv=muv[(muv>0)&(muv<10)&(muv!=nextm)] nomove=(length(muv)==0)||(i>1e6) if (!nomove) t=sample(rep(muv,2),1, prob=1/(5.5-rep(muv,2))^4) i=i+1} return(i)}

which returns unlimited values on repeated runs. However, I was wrong and the R code unable to dismiss my a priori!, as later discussions with Robin and Julien at Paris-Dauphine exhibited ways of terminating the random walk in 18, then 15, then 14 steps! The idea was to push the target to one of the endpoints because it would then have no option but turning back: an opening pattern like 2, 3, 4, 5, 6, 7, 8, 8 would take care of a hidden object starting in an even drawer, while the following 7, 6, 5, 4, 3, 2 openings would terminate any random path starting from an odd drawer. To double check:

grawl=function(){ len=0;muvz=c(3:8,8:1) for (t in 1:9){ i=1;m=muvz[i];nomove=(t==m) while (!nomove){ i=i+1;m=muvz[i];muv=c(t-1,t+1) muv=muv[(muv>0)&(muv<10)&(muv!=m)] nomove=(length(muv)==0) if (!nomove) t=sample(rep(muv,2),1)} len=max(len,i)} return(len)}

produces the value 14.