Pieters bash scripts
Documentation for the bash scripts I have published
Loading...
Searching...
No Matches
monty_hall.sh File Reference

This script simulates the Monty Hall problem to help decide on a strategy. More...

Go to the source code of this file.

Functions

 swap ($arg1, $arg2)
 Swap your choice from the chosen one to the other unrevealed door.

Variables

if(func_num_args() -lt 1) else
 $winsa = 0
 Number of wins for player A.
 $winsb = 0
 Number of wins for player B.
 $prizepos = 0
 Position of the prize.
 $guess = 0
 Original guess.
 $i = 1
 Counter for the number of rounds already done.
 $rand [0] = 0
 Counts how often the random number was 0. Used for statistics at the end of the script.
 $rand [1] = 0
 Counts how often the random number was 1. Used for statistics at the end of the script.
 $rand [2] = 0
 Counts how often the random number was 2. Used for statistics at the end of the script.
 $apercent = winsa*100/i
 Percentage of wins for player A.
 $bpercent = winsb*100/i
 Percentage of wins for player B.

Detailed Description

This script simulates the Monty Hall problem to help decide on a strategy.

Author: Pieter van der Star (info@.nosp@m.piet.nosp@m.ervan.nosp@m.ders.nosp@m.tar.n.nosp@m.l) Modifications by: (unmodified)

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.

Definition in file monty_hall.sh.

Function Documentation

◆ swap()

swap ( $arg1,
$arg2 )

Swap your choice from the chosen one to the other unrevealed door.

Parameters
$arg1Position of the prize.
$arg2Position of the choice.
Returns
New choice position.

Definition at line 85 of file monty_hall.sh.

Variable Documentation

◆ $apercent

$apercent = winsa*100/i

Percentage of wins for player A.

Definition at line 156 of file monty_hall.sh.

◆ $bpercent

$bpercent = winsb*100/i

Percentage of wins for player B.

Definition at line 158 of file monty_hall.sh.

◆ $guess

$guess = 0

Original guess.

Definition at line 112 of file monty_hall.sh.

◆ $i

$i = 1

Counter for the number of rounds already done.

Definition at line 114 of file monty_hall.sh.

◆ $prizepos

$prizepos = 0

Position of the prize.

Definition at line 110 of file monty_hall.sh.

◆ $rand [1/3]

$rand[0] = 0

Counts how often the random number was 0. Used for statistics at the end of the script.

Definition at line 116 of file monty_hall.sh.

◆ $rand [2/3]

$rand[1] = 0

Counts how often the random number was 1. Used for statistics at the end of the script.

Definition at line 118 of file monty_hall.sh.

◆ $rand [3/3]

$rand[2] = 0

Counts how often the random number was 2. Used for statistics at the end of the script.

Definition at line 120 of file monty_hall.sh.

◆ $winsa

$winsa = 0

Number of wins for player A.

Definition at line 106 of file monty_hall.sh.

◆ $winsb

$winsb = 0

Number of wins for player B.

Definition at line 108 of file monty_hall.sh.

◆ else

if (func_num_args() -lt 2) else
Initial value:
{
$numrounds = $1

Definition at line 72 of file monty_hall.sh.