#! perl -slw use strict; use List::Util qw[ shuffle ]; my( $stick, $switch, $skip_goat, $skip_car ) = (0, 0, 0, 0); for ( 1 .. 100_000 ) { ## Randomly hide the prizes behind the doors. my @doors = shuffle 'car', 'goat', 'goat'; ## Pick a door my $choice = int rand 3; #### ## Uncomment the option you want here to see different scenarios. ### ## Option 1: The host opens a door that I didn't pick ## and that isn't the car #my @available = grep{ $_ != $choice and $doors[ $_ ] ne 'car' } 0 .. 2; ## Option 2: The host opens a random door #my @available = grep{ $_ != $choice } 0 .. 2; ## Option 3: The host tries to be malicious #my @available = grep{ $_ != $choice and $doors[ $_ ] eq 'car' } 0 .. 2; #@available = grep{ $_ != $choice } 0..2 if not @available; #### ## End of options #### # Monty chooses which door to open from the choices # that he might make. my $opened = $available[rand(@available)]; if ($doors[$opened] eq 'car') { $doors[ $choice ] eq 'car' ? $skip_car++ : $skip_goat++; next; } ## Count my wins if I stick or switch $doors[ $choice ] eq 'car' ? $stick++ : $switch++; } printf "Odds of Not getting here if you were originally right: %.3f Not getting here if you were originally wrong: %.3f Win if you don't switch: %.3f Win if you do switch: %.3f\n", $skip_car / (( $stick + $switch + $skip_goat + $skip_car) / 100 ), $skip_goat / (( $stick + $switch + $skip_goat + $skip_car) / 100 ), $stick / (( $stick + $switch) / 100 ), $switch / (( $stick + $switch) / 100 )