Skip to content

alphafoobar/MontyHallProblem

 
 

Repository files navigation

Build Status codecov

Monty Hall Problem

This simple application is an exploration into a solution to the Monty Hall problem. Though the application explores the Monty Hall problem, this fork attempts to illustrate how improving the readability of the code base can make the solution easier to understand. Even with minimal commenting.

The main class is MontyHallProblem and can be run without providing arguments. It creates a counter to keep track of the results and prints a summary of results and the end of execution. For each iteration (or contest) run, a collection of doors is created to keep track of the contestant and host selections.

Running this application from the command line

mvn exec:java -Dexec.mainClass="MontyHallProblem"

Running alternatively sized execution

You must edit the constants in the MontyHallProblem class:

  1. NUMBER_OF_TRIALS: A larger number provides a higher confidence in the statistical result.
  2. NUMBER_OF_DOORS: 3 is the most common, but any number will work.

Logging

Is handled by slf4j - check the configuration in the resources directory.

What does this program do?

  1. Loops through the specified number of trials.
    1. Creates a structure representing the doors, where only one hides a car.
    2. A random door is selected by the contestant as their original choice.
    3. A random door that is a goat is revealed to the contestant.
    4. A random door is selected by the contestant as their switch selection.
    5. A running count of choice outcomes is kept.
  2. Finally a summary of the outcomes is printed.

Background to this implementation

From the June 2015 Philly Java Users Group Meeting.

We had a side discussion on code commenting a few people wanted the discussion documented for future reference.

@mgeiser added the slide deck and created this example repo.

  • The slides of interest regarding commenting are the last 5 slides of the deck.
  • This fork intends to explore an alternative school of thought.

    Comments highlight code that can be improved.

Further reading

  1. http://montyhallproblem.com/
  2. http://en.wikipedia.org/wiki/Monty_Hall_problem

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%