blind monty hall

As I was waiting for my boat on a French Guiana beach last week, I thought back about a recent riddle from The Riddler where an item does a random walk over a sequence of N integers. Behind doors. The player opens a door at the same rate as the item, door that closes immediately after. What is the fastest strategy to catch the item? With a small value of N, it seemed that repeating the same door twice and moving from 1 to N and backward was eventually uncovering the item.

Here is the cRude code I later wrote to check whether or not this was working:

  p=1+t%%N #starting item position
  h=v=s=m=1 #h=door, v=attempt number, s=direction, m=repeat number
  while(h-p){
    p=ifelse(p==1,2, #no choice
             ifelse(p==N,N-1, #no choice
                    ifelse(p==h-1,p-1, #avoid door
                           ifelse(p==h+1,p+1, #avoid door
                                  p+sample(c(-1,1),1))))) #random
    m=m+1
    if(m>2){
      h=h+s;m=1
      if(h>N){
        h=N-1;s=-1}
      if(!h){
        s=1;h=2}
      }
    v=v+1

and the outcome for N=100 was a maximum equal to 198. The optimal strategy leads to 196 as repeating the extreme doors is not useful.

2 Responses to “blind monty hall”

  1. […] article was first published on R – Xi'an's Og, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here) […]

  2. […] by data_admin [This article was first published on R – Xi’an’s Og, and kindly contributed to R-bloggers]. (You can report issue about the content on this page […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: