Thursday, December 24, 2015

Those Distracting Smartphones

The most recent Riddle from FiveThirtyEight has me stumped and feeling what it is like to be a frustrated graduate student again.  No matter how much I worked through different probabilities using different approaches, I couldn't find a pattern that would simplify the problem.  And what's worse, there is no professor I can go visit in office hours. I've even tried Tweeting the writers of the problem for a hint, but to no avail.

The Riddle is quoted below for convenience.
You’ve just finished unwrapping your holiday presents. You and your sister got brand-new smartphones, opening them at the same moment. You immediately both start doing important tasks on the Internet, and each task you do takes one to five minutes. (All tasks take exactly one, two, three, four or five minutes, with an equal probability of each). After each task, you have a brief moment of clarity. During these, you remember that you and your sister are supposed to join the rest of the family for dinner and that you promised each other you’d arrive together. You ask if your sister is ready to eat, but if she is still in the middle of a task, she asks for time to finish it. In that case, you now have time to kill, so you start a new task (again, it will take one, two, three, four or five minutes, exactly, with an equal probability of each). If she asks you if it’s time for dinner while you’re still busy, you ask for time to finish up and she starts a new task and so on. From the moment you first open your gifts, how long on average does it take for both of you to be between tasks at the same time so you can finally eat? (You can assume the “moments of clarity” are so brief as to take no measurable time at all.)
 By using a random uniform number generator in R, I created two sequences of random integers from 1 to 5, call them X and Y.  To illustrate, suppose the first set of random sequences were given as X = {4,3,4,1,5,...} and Y={3,5,1,2,5,...}.

I would then ask R to compare the first two values of 4 and 3.  If they happened to match, I would ask for that matching number. If one was smaller than the other (as is the case with this example), I would ask R to take the smaller value and add to it the next number in the sequence.  In this case, we get 3+5=8.

Now, I ask R to compare 4 and 8.  No match?  Then 4+3=7 in the X sequence. Compare 7 and 8.  No match?  Then 7+4 = 11 still in the X sequence.  Compare 8 and 11.  Still no match, so now jump back over to the Y sequence and get 8+1=9.  Compare 9 and 11, and find no match, so 9+2 =11 in the Y sequence.  Finally! Since 11 and 11 match, I have R report that number.

Then, I asked R to do that 1,000 times and give me a mean of all the lengths it produced.  Again.  Again.  Again.

The pattern that results makes me want to guess that 9 is either the correct answer or very close to the correct answer.

Please, please, please, somebody chime in with the trick to solving this problem without simulation.  I'm going insane.

For the coding geeks out there, this is what I did:


  1. Thanks for sharing the code.
    My early guess ...3(pi)...still some work to do though.

  2. Here's the running average / pi:
    That's where my guess comes from.

  3. Try the following to get plots that level off at 9 quite a bit. Instead of return(mean(Times)), put the following:

    newTimes<- c()
    for(i in 1:n){
    newTimes <- c(newTimes, mean(Times[1:i]))
    return(plot(newTimes, type="l", xlab="Time"))

  4. I actually ran mine on Google Sheets and obviously that is where my graph is from.