montehall

A Monte Carlo Machine for the Monty Hall Problem

https://github.com/oboukli/montehall

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (10.2%) to scientific vocabulary

Keywords

monty-hall-problem probabilities randomness simulation
Last synced: 6 months ago · JSON representation ·

Repository

A Monte Carlo Machine for the Monty Hall Problem

Basic Info
  • Host: GitHub
  • Owner: oboukli
  • License: mit
  • Language: TypeScript
  • Default Branch: main
  • Homepage:
  • Size: 710 KB
Statistics
  • Stars: 0
  • Watchers: 0
  • Forks: 1
  • Open Issues: 1
  • Releases: 8
Topics
monty-hall-problem probabilities randomness simulation
Created over 8 years ago · Last pushed over 1 year ago
Metadata Files
Readme License Citation

README.md

Montehall: a Monte Carlo machine for the Monty Hall problem

Build and test Azure Pipelines build status CodeQL Known vulnerabilities Quality Gate Status

Code style: prettier

An over-engineered CLI app, and an experiment with TypeScript/JavaScript (ECMAScript) aimed at:

  1. Creating a simulation of the famous counterintuitive Monty Hall problem
  2. Solving the strategy problem with Monte Carlo methods
  3. Creating a simulation of a general Montehall Problem with $n$ number of doors
  4. Producing fairly readable code and Node.js solution suitable for a pretty good practice tutorial.

Inspired by Numberphile's Monty Hall problem video.

Monty Hall Problem - Numberphile

Setup

Node.js (latest v16.x, or higher) and NPM (v9.x) are required to run the app:

shell npm install npm run build

Or, using Docker and Bash (recommended)

bash docker pull node docker run --rm --volume=$(pwd):/src --workdir="/src" node npm install docker run --rm --volume=$(pwd):/src --workdir="/src" node npm run build

Running the CLI app

Running the default simulation with a player that does not switch:

shell npx montehall

or, with Docker and Bash

bash docker run --rm --volume="$(pwd):/src" --workdir="/src" node npx montehall

A player who does not switches their door pick should statistically win 1/3 of the games, given a sufficiently large number of random game attempts. However, a prudent, or "wise," player who switches pick should win 2/3 of the games, which can be simulated using the --wise option:

shell npx montehall --wise

A list of available options is accessible from the CLI:

shell npx montehall --help

Number of game simulations

The default number of simulated games is 16384. This can be changed using the --games option, or by changing the value for the games key in the config.json configuration file.

General Monte Hall problem

A standard (default) game has three doors. A general game has $n$ doors.

The CLI option --doors <number> can be used to specify the number of doors.

Examples:

shell npx montehall --doors 100 npx montehall --doors 181 --games 1000 --wise

High-quality results

A randomness source is required to simulate the games. Achieving high-quality simulation results requires a high-quality randomness source.

The default source of randomness used is a fast pseudo one: the Math.random() function.

A higher quality randomness source

For a higher quality, but slower, randomness source, use the --random advanced option, which employs a cryptographically secure pseudorandom number generator (CSPRNG.)

shell npx montehall --wise --random advanced

Using pre-generated random numbers (experimental)

A text file of numbers (random positive integers) can be loaded to run a deterministic simulation.

The file path can be passed as a CLI option:

shell npx montehall --games 100 --table-file vendor/numbers.txt

Or, alternatively, the file path can be configured in config.json.

Example:

json { "numbersFilePath": "./data/numbers.txt" }

shell npx montehall --games 100 --random table

The file must have one number per text line. Example:

text 1 1 0 1 2 1 0

See vendor/numbers.txt for a sample file.

Technical showcases

Partial list of showcases, in alphabetical order:

  • Asynchronous programming
  • Azure Pipelines
  • Behavior-driven development (BDD)
  • CodeQL
  • Coding without null
  • Coding without classes
  • Command-line interface (CLI)
  • Commander.js
  • Continuous integration
  • Conventional Commits
  • DevSkim
  • Distribution package clean of development dependencies
  • ECMAScript Modules
  • ESLint
  • Functional programming
  • GitHub Actions
  • High code test coverage
  • Markdown
  • Markdownlint
  • Node.js
  • NPM
  • Prettier
  • SonarCloud
  • Strict static rules and type safety
  • Symantec versioning
  • TypeScript
  • Unbiased pseudo-randomness
  • Unit testing with Jest (and Jasmine)

License

This software is released under an MIT-style license. Copyright © 2017-2023 Omar Boukli-Hacene.


Written for the joy of it 🐻

Owner

  • Name: Omar Boukli-Hacene
  • Login: oboukli
  • Kind: user

Citation (CITATION.cff)

cff-version: 1.2.0
title: OBoukli Montehall
message: >-
  If you use this software, kindly cite it using the
  metadata from this file.
type: software
authors:
  - given-names: Omar
    family-names: Boukli Hacene
repository-code: "https://github.com/oboukli/montehall"
abstract: >-
  A software Monte Carlo machine for the Monty Hall problem.
license: MIT

GitHub Events

Total
Last Year

Dependencies

package-lock.json npm
  • @types/jasmine 4.0.2 development
  • @types/node 16.11.26 development
  • balanced-match 1.0.2 development
  • brace-expansion 1.1.11 development
  • concat-map 0.0.1 development
  • fs.realpath 1.0.0 development
  • glob 7.2.0 development
  • inflight 1.0.6 development
  • inherits 2.0.4 development
  • jasmine 4.1.0 development
  • jasmine-core 4.1.0 development
  • minimatch 3.1.2 development
  • once 1.4.0 development
  • path-is-absolute 1.0.1 development
  • typescript 4.6.3 development
  • wrappy 1.0.2 development
  • bluebird 3.7.2
  • commander 4.1.1
  • create-error 0.3.1
  • random-number-csprng 1.0.2
package.json npm
  • @types/jasmine ^4.0.2 development
  • @types/node ^16.11.26 development
  • jasmine ^4.1.0 development
  • typescript ^4.6.3 development
  • commander ^4.1.1
  • random-number-csprng ^1.0.2
.github/workflows/build-and-test.yml actions
  • actions/checkout v3 composite
  • actions/setup-node v3 composite
  • actions/upload-artifact v3 composite
.github/workflows/codeql-analysis.yml actions
  • actions/checkout v3 composite
  • github/codeql-action/analyze v2 composite
  • github/codeql-action/init v2 composite
.github/workflows/lint.yml actions
  • actions/checkout v3 composite