#! perl -slw use strict; use List::Util qw[ shuffle ]; our $TRIALS ||= 1_000_000; my $DIVISOR = $TRIALS / 100; my( $stick, $switch, $newChoice ); for my $try ( 1 .. $TRIALS ) { ## Randomly hide the prizes behind the doors. my @doors = shuffle 'car', 'goat', 'goat'; ## Pick a door my $choice = int rand 3; ## The host opens a door that I didn't pick ## and that isn't the car my $opened = grep{ $_ != $choice and $doors[ $_ ] ne 'car' } 0 .. 2; ## Count my wins if I stick or switch $doors[ $choice ] eq 'car' ? $stick++ : $switch++; ## Make a new choice from the remaining two my $new = ( grep{ $_ != $opened } 0 .. 2 ) [ rand 2 ]; ## And if I make a completely new random choice. $doors[ $new ] eq 'car' and $newChoice++; } printf "Odds of Choose again: %.3f Win if you don't switch: %.3f Win if you do switch: %.3f\n", $newChoice / $DIVISOR, $stick / $DIVISOR, $switch / $DIVISOR; __END__ P:\test>test Odds of Choose again: 33.331 Win if you don't switch: 33.286 Win if you do switch: 66.714 P:\test>test Odds of Choose again: 33.370 Win if you don't switch: 33.353 Win if you do switch: 66.647