Two-Box Problem in Julia

Stephanie Simoes challenges us to the "two-box problem."

View this post on Instagram

A post shared by Critikid | Stephanie Simoes (@critikid)

This problem is similar to the infamous Monty Hall problem. In the two-box problem, there are two boxes, each containing two notes. One of the boxes has \$100 notes. The other box has one \$100 note and one \$1 note.

Suppose that, without looking, one successfully pulls a \$100 note from a box. Now you get a second chance to pull another note from either box. Should you change boxes?

The above function, implemented in Julia, simulates our two-box problem by returning the total if we do or do not change boxes. This function can only return 101 or 200. We now take the average from one million experiments changing or not changing boxes.

Based on these experimental results, you should change boxes to win (on average) the two-box problem.

$$ \begin{aligned} p(100 | \textrm{change}) &= 0.75 \\ p(100 | \textrm{no change}) &= 0.50 \end{aligned} $$

Why? I will hazard an explanation, but let me disclaim that problems like this are famously tricky and I might be wrong.

Let us start with with the case where you don't change. You've already chosen a \$100 from the first box, so now it is obviously 50:50 whether you had the box with the \$1 or not.

The second case, where we do change boxes, is less obvious. We enumerate the possibilities that follow having drawn \$100 from the first box.

  1. ($p=0.50$) The current box contains a \$100. We switch to the other box, which contains \$1 and \$100.
    a. ($p=0.25$) We randomly choose \$1.
    b. ($p=0.25$) We randomly choose \$100.
  2. ($p=0.50$) The current box contains a \$1. We switch to the other box, which contains \$100 and another \$100.
    a. ($p=0.25$) We randomly choose \$100.
    b. ($p=0.25$) We randomly choose the other \$100.

Therefore, $p(100 | \textrm{change}) = 1 - p(1 | \textrm{change}) = 1 - 0.25 = 0.75$.