### Easiest $100 I'll Ever Make

Recently, before boarding a flight up to Hamilton Island for a $WORK ~~junket~~ conference, I purchased a puzzle book. On the flight, I shared the puzzles amongst colleagues, and fun was had. One particularly tricky puzzle confounded us all, although I recognised it as a variant of the Monty Hall problem. Alarm bells should be going off at this point for those who have debated the subject in the past…

Anyway, one colleague didn’t believe that the answer in the back of the book was correct, and he offered to bet that by running a computer simulation he could prove the book (and me) wrong. I’m not a betting person, but for some reason, possibly euphoria at the prospect of the upcoming ~~partying~~ seminars, I immediately accepted his bet, wagering $100.

What follows is my attempt to win that bet.

So that there is no argument, I’ll reproduce the exact wording of the problem as stated in the puzzle book:

90.Four different pieces of candy are placed in a bag. One is chocolate, one is caramel, and two are licorice. Without looking in the bag, I draw two pieces of candy from it, and place one of them, which is licorice, on a table.What are the chances that the second piece of candy I have in my hand is the other piece of licorice candy?

My colleague said the answer is ⅓, simply because the candy in the hand can only be one of three other candies still unseen. Of course this is a classic Monty Hall conditional probability problem, and he is quite wrong.

The key insight to this puzzle is that when I (as the person stating the puzzle) am putting the piece of candy on the table I am *selecting* it. Just as Monty does when he picks the door with the goat. There’s no element of randomness.

So the correct way to assess the probability is to think about the possible combinations of candies in your hand. There are six: the chocolate and caramel, caramel and either licorice, chocolate and either licorice, and the two licorice. Now we know that one of these combinations, the chocolate and caramel, is not possible. There are five remaining possibilities, and one of these is the one we want. Hence the odds are ⅕.

Anyway the agreed method of settling the bet was to write a computer simulation, so I did just that. Here is the output of a sample run:

Out of 1000000 tries, two licorices were extracted 200432 times. Estimated probability = 0.200432

We have a winner. Thanks JT, cash will be fine.

Here is the C++ code:

#include <stdlib.h> #include <algorithm> #include <iostream> #include <tr1/array> const long iterations = 1000000; enum candy { chocolate, caramel, licorice }; int main(int argc, char *argv[]) { ::srand(::time(NULL)); // Number of times we've pulled out two licorice from the bag long two_licorice = 0; for(long i = 0; i < iterations;) { // put the candies in the bag std::tr1::array<candy, 4> bag = {{ chocolate, caramel, licorice, licorice }}; // shuffle them std::random_shuffle(bag.begin(), bag.end()); // pull out two std::tr1::array<candy, 2> hand = {{ bag[0], bag[1] }}; // At least one of the candies we pick out must be a licorice otherwise it doesn't count. if (hand[0] != licorice && hand[1] != licorice) continue; // Count if we've got both licorice if (hand[0] == licorice && hand[1] == licorice) ++two_licorice; ++i; } std::cout << "Out of " << iterations << " tries, two licorices were extracted " << two_licorice << " times.\n" << "Estimated probability = " << static_cast<double>(two_licorice) / static_cast<double>(iterations) << std::endl; return 0; }

## 4 Comments