I first heard of the Monty Hall Problem while watching the TV show "Numb3rs".
The main character of the show is a math genius who frequently helps solve crimes using his math skills.
I don't remember the details of the episode, but they were talking about game theory and the Monty Hall problem came up.
It came to my attention again today while reading this StackExchange Question
Here's how it goes:
Suppose you're on a game show, and you're given the choice of three doors: Behind one door is a car; behind the others, goats. You pick a door, say No. 1, and the host, who knows what's behind the doors, opens another door, say No. 3, which has a goat. He then says to you, "Do you want to pick door No. 2?"
Is it to your advantage to switch your choice?
It turns out that, even if it doesn't seem intuitive, you are more likely to win if you switch. Mathematicians argued about it, but have finally agreed.
I wanted to write a quick bit of code to see what probability I came up with. My language of choice at the moment is PHP, so here it is:
You can run it here:
http://sandbox.onlinephpfunctions.com/code/12a9471a3c5febfe08db2e18af07ad4f2037aa7f
(Don't be confused. In that sandbox, instead of "doors", I used "cards" )
<?php
$player_should_keep=0;
$player_should_swap=0;
for ($i=0; $i <= 100000; $i++) {
$doors=array('car','goat','goat');
shuffle($doors);
$known_car=array_search('car', $doors);
$player_choice=rand(0,2);
//trying to write this made it obvious to me WHY you should always switch
$hosts_choices=$doors;
unset($hosts_choices[$player_choice]); // The host cannot choose the player's door.
unset($hosts_choices[$known_car]); // The host cannot choose the car.
$hck=array_keys($hosts_choices);
shuffle($hck);
$hosts_choice=reset($hck); // at this point, the host will only have 1 or 2 doors to choose from.
unset($doors[$hosts_choice]);
if ($doors[$player_choice]=='car') {
$player_should_keep++;
}else{
$player_should_swap++;
}
}
echo 'Players who did not swap would have won '. $player_should_keep . ' times'."
\n\n";
echo 'Players who did swap would have won '. $player_should_swap . ' times'."
\n\n";
?>
The funny thing is, I realized after I wrote it that I could comment out the biggest part of the logic, and the code still works. I never actually did anything with the edited version of the $doors array. I could, if there were a skeptic that needed to see actual guesses and actual outcomes, but it isn't really necessary.
Think of it this way, if I have a 1:3 chance selecting the car on the first go, there is a 2:3 chance I didn't choose a car. The host always removes a goat, so my choice is to believe that my 1:3 guess was right and stick to it, or to decide that I was probably wrong, and therefor switch. In the 2/3 of cases, where a goat was chosen and the other goat was removed, the only door left is the winning door.
Because I stepped through the logic in the PHP above, I could actually write a guessing routine, but I shortened it when I realized all I had to calculate was if the player SHOULD switch. Then, thinking about and writing this blog post made me realize how little of the PHP code I actually needed, and how obvious (retrospectively obvious) it is that switching is the preferred choice.
The author worked as a PHP / MySQL programmer for a Tampa Web Design Company for several years. He has now started his own Web Developer company and is recruiting clients.
Wednesday, July 27, 2016
Wednesday, June 8, 2016
there is no God the coffee pot
So, I was talking to my inlaws about CoWork Tampa, where I am a member, and about the fact that they have a single cup coffee machine. I was about to do a google search for "Flavia Coffee Pods" but I hit the microphone icon instead of the text box.
Google then did a search for the following text.
On my mobile phone, I could only see the first few words, so I visited https://history.google.com/history/audio where I could get the full text and actually listen to the audio it had recorded of me. I did my own transcript of what it actually overheard and turned into the above comical rant.
The moral, be careful when you hit the google search box 'cause voice search is crazy!
Google then did a search for the following text.
there is no God the coffee pot in there and everyone was so my mom a couple times but mostly just going to make up a singleWe found this hilarious!
On my mobile phone, I could only see the first few words, so I visited https://history.google.com/history/audio where I could get the full text and actually listen to the audio it had recorded of me. I did my own transcript of what it actually overheard and turned into the above comical rant.
there is uh, they've got a uh coffee pot there, and every once in a while somebody will go make up a pot, but most people just go and make up a single cup.
The moral, be careful when you hit the google search box 'cause voice search is crazy!
Tuesday, May 24, 2016
Dark Roast Coffee is an insult to a good bean!
I am not a coffee aficionado. I like coffee ice cream. I like coffee flavored candy, but if you serve me Folgers, Maxwell House, or just about any coffee I've ever encountered, I have to smother it in cream and sugar until it resembles those previously mentioned tasty treats.
I thought that's just how it is! Some seem to take the idea of drinking darker and darker roasts as a challenge in the same way that I might inflict upon myself the delights of habeneros, ghosts and scorpions, or really strong sauerkraut or kimchi.
I thought that's just how it is! Some seem to take the idea of drinking darker and darker roasts as a challenge in the same way that I might inflict upon myself the delights of habeneros, ghosts and scorpions, or really strong sauerkraut or kimchi.
Thursday, May 19, 2016
Wireless Fidelity?
This morning, as the WiFi signal waxed and waned from her tablet, my wife asked me "What's the 'fi' in 'WiFi' mean."
I told her it really doesn't mean anything, but it was intended to be familiar, thanks to professional audio equipment known as "Hi-Fi" for High Fidelity that means the output is as close to the input as possible, but that "Wireless Fidelity" really didn't mean anything.
I told her it really doesn't mean anything, but it was intended to be familiar, thanks to professional audio equipment known as "Hi-Fi" for High Fidelity that means the output is as close to the input as possible, but that "Wireless Fidelity" really didn't mean anything.
Friday, May 13, 2016
Approaching 5000 total views
I started this blog a little over 8 1/2 years ago, on 8/31/07.
I posted less then 20 times that year, and even less frequently in the following years, until I started running my own business and blogging about my clients, in addition to my own opinions and ramblings.
About a year ago, I posted that I had hit 3000 veiws, so getting to 5k (a 2k improvement) in just over a year is again encouraging.
I posted less then 20 times that year, and even less frequently in the following years, until I started running my own business and blogging about my clients, in addition to my own opinions and ramblings.
About a year ago, I posted that I had hit 3000 veiws, so getting to 5k (a 2k improvement) in just over a year is again encouraging.
Monday, May 2, 2016
Tampa Land Clearing
Not all tree trimming is as straight forward as showing up with a truck and chainsaws. There may be environmental concerns such as sensitive wildlife or nearby creeks, streams or rivers. Perhaps there's work to be done near a grand oak or other protected tree and the weight of heavy equipment might compact the soil or otherwise damage it's roots.
Whatever the issue, there are times when hand-clearing is needed. When that time comes, trust a professional to do the job right, to protect the environment, to protect old growth trees, and to get your lot looking just the way it should.
Whatever the issue, there are times when hand-clearing is needed. When that time comes, trust a professional to do the job right, to protect the environment, to protect old growth trees, and to get your lot looking just the way it should.
Subscribe to:
Posts (Atom)