#!/usr/bin/perl

#
# Monty Hall Simulation 1 - No Switching
# When you choose a door, you always keep it.
#

$c = 0;		# Counter
$t = 10000;	# Trials
$d = 3;		# Door with car; no loss of generality.

for($i = 0; $i < $t; $i++) {

  # Pick a door at random
  $p = int(rand(3)) + 1;

  # If I picked the car door, then pick $g, the goat door, from 1 and 2
  if ($d == $p) {$g = int(rand(2)) + 1;}

  # If I didn't pick the right door, pick $g as the last unassigned door
  else {$g = (3 - $p);}

  # If I picked the right door, advance the counter by one.

  if ($p == $d) {$c++;}

}

# Print the results

$pct = ($c / $t) * 100;
print "Without switching, the percentage is $pct%\n";
