Silly Logic Games: Part 1

By derek.illchuk, June 9, 2010 12:57 am

Derek: I flip two coins, hidden from your view, and call out, “one is heads”.  Can you tell me the odds that both coins match?

Dr. Logic: Yes!  1 in 3!  You see, the possibilities are as follows: HH, HT, TH, TT.  But, you said heads, so the last is excluded.  Hence, the possibilities are HH, HT, TH, one matching and two not.  Voila!

Derek: Uh, the odds are 1 in 2. <whisper whisper whisper to Dr. Logic>

Dr. Logic: Oh my!  You’re right!

 

So, what’s going on?

When I said, “one is heads”, Dr. Logic did not consider how I chose what to say.  And how’s that?  I simply looked at the left-most coin and called out its state, heads or tails, as in “one is heads” or “one is tails”.  Here’s how that plays out:

“One is heads” means HH, HT and yields a match 1 in 2

“One is tails” means TH, TT yields a match 1 in 2

So, when I asked, “Can you tell me the odds that both coins match?”, Dr. Logic should have said, “Not yet, I still have a question.”

 

Code test

I like to see probability in action, so I’ve coded this to run a million times.

<?php
 
$heads = 0;
$tails = 1;
$counts = array(
  'heads' => 0,
  'tails' => 0,
  'one_is_heads' => array(
    'match'    => 0,
    'no_match' => 0
  ),
  'one_is_tails' => array(
    'match'    => 0,
    'no_match' => 0
  )
);
for ( $i = 0; $i < 1000000; $i++ ) {
  $coin1 = ( rand(0, 1)%2 == 0 )? $heads : $tails;
  if ( $coin1 == $heads ) $counts['heads']++;
  else if ( $coin1 == $tails ) $counts['tails']++;
 
  $coin2 = ( rand(0, 1)%2 == 0 )? $heads : $tails;
  if ( $coin2 == $heads ) $counts['heads']++;
  else if ( $coin2 == $tails ) $counts['tails']++;
 
  $count_ix = ( $coin1 == $heads )? 'one_is_heads' : 'one_is_tails';
  $match_ix = ( $coin1 == $coin2 )? 'match' : 'no_match';
  $counts[$count_ix][$match_ix]++;
}
print_r($counts);
 

Result:
Everything is 1 in 2.

Array
(
    [heads] => 1000658
    [tails] => 999342
    [one_is_heads] => Array
        (
            [match] => 250567
            [no_match] => 249449
        )
 
    [one_is_tails] => Array
        (
            [match] => 249909
            [no_match] => 250075
        )
 
)

Leave a Reply

Panorama Theme by Themocracy