Example Code

Solving The Monty Hall Paradox with LabVIEW

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview

This example aims to prove the Monty Hall Paradox using LabVIEW to automate a large sample size.

 

Description

The Monty Hall Paradox is a weird and wonderful statistical conundrum, which seems to defy the laws of mathematics. Having struggled to get my head around the problem, I created a LabVIEW application that definitively proves the theory.

 

Requirements

  • LabVIEW 2013 (or compatible).

 

Steps to Implement or Execute Code

  1. LabVIEW begins by randomizing the doors.
  2. Choose a door.
  3. LabVIEW opens up one of the doors that does not contain the prize.
  4. You now have the option of changing your decision to the other door.
  5. LabVIEW opens all doors, and records whether you have won or lost.
  6. Click the Prove It button to automatically run the same decision over a large sample size.
  7. Click the Stop button to exit.

Additional Information or References 

The Monty Hall Paradox:

You are a contestant on a TV game show. The game show host, complete with perfectly coiffed hair and dazzlingly white smile, is stood in front of three closed doors. Behind these doors are one luxury sports car and two goats. Assuming that you would rather win a new car than a new goat, you are tasked with guessing which door hides the car.

44x3sgvy-1370406223.jpgNo skill required - this is a game of pure chance.

 

You make your choice. At this moment, your chances of winning the car are 1 in 3.

 

But here’s the curve ball, knowing the location of the car, the host opens one of the remaining doors to reveal a goat. He then offers you the opportunity to switch your choice for the other remaining closed door.

 

Do you take him up on the offer? What is the probability of winning the car if you switch your initial choice?

 

"Still 33%, right?"

 

Wrong! Only two closed doors remain. One must hide the car! Please try again.

 

"Ahhh, of course! So, statistically speaking, switching doors will not change my likelihood of winning the car. Either door now has a 50% chance of winning!"

 

Wrong again! Sticking with your original choice still gives you a 33% chance of winning... but changing your mind will DOUBLE your chances of winning.

 

The code:

This app allows you to play the afformentioned game, while LabVIEW tracks your win/lose statistics. I would recommend downloading the code (at the bottom of the page) and playing a few games yourself - thereby familiarising yourself with the flow and, more importantly, the Monty Hall Paradox.

 

Once you have played a few rounds, click the “prove it” button. LabVIEW will keep track of the win percentage as it automatically plays a statistically significant number of games for you (specifically, 100,000 games)

 

All you have to do is select whether you want LabVIEW to always stick or always switch.


prove it.JPG

Additional Information:

The application was developed with a number of interesting coding techniques.

 

The LabVIEW Picture Control is used for intuitive player feedback

A custom, event based dialog box provides the prove it! window

Custom Function Global Variables (FGV) allows the app track game statistics using an uninitialised shift register

The app is architected around the flexible/scalable state-machine design pattern.

**This document has been updated to meet the current required format for the NI Code Exchange.**

Rich Roberts
Senior Marketing Engineer, National Instruments
Connect on LinkedIn: https://www.linkedin.com/in/richard-roberts-4176a27b/

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
JLHaworth
Member
Member
on

Would you be able to post a copy that could open in LV 2012?

RER
NI Employee (retired)
on

Thanks for your interest JLHaworth!

I have just posted a 2012 version. Enjoy!

Rich Roberts
Senior Marketing Engineer, National Instruments
Connect on LinkedIn: https://www.linkedin.com/in/richard-roberts-4176a27b/
szerpp
Member
Member
on

Would you be able to post a copy that could open in LV 2011?