Browse Source

eureka

Ok, so after reading some Wikipedias we get it.

a) in order to answer the question, you don't have to give a shit
   about which door monty eliminates.

b) we were effectively just doing a coin toss at the end.
main
user 10 years ago
parent
commit
7f6f107411
1 changed files with 15 additions and 13 deletions
  1. +15
    -13
      monty.pl

+ 15
- 13
monty.pl View File

@ -4,6 +4,9 @@ use strict;
use warnings;
use 5.10.0;
# NOTE: we got the thing about the goat being the prize backwards
# from how this is usually defined.
# basic setup:
# you get 3 doors
# - initially, you pick a door at random
@ -13,24 +16,23 @@ use 5.10.0;
my ($switched, $unswitched) = (0, 0);
my $doors = 3;
for (my $i = 0; $i < 100000000; $i++) {
for (my $i = 0; $i < 1000000; $i++) {
my $goat = int(rand($doors));
my $initial_selection = int(rand($doors));
my $host_eliminates = int(rand($doors));
until (($host_eliminates != $initial_selection) && ($host_eliminates != $goat)) {
$host_eliminates = int(rand($doors));
}
my $final_selection = int(rand($doors));
until ($final_selection != $host_eliminates) {
$final_selection = int(rand($doors));
}
# my $host_eliminates = int(rand($doors));
# until (($host_eliminates != $initial_selection) && ($host_eliminates != $goat)) {
# $host_eliminates = int(rand($doors));
# }
my $result = ($final_selection == $goat);
# THIS IS OUR BUG (i kind of think)
# my $final_selection = int(rand($doors));
# until ($final_selection != $host_eliminates) {
# $final_selection = int(rand($doors));
# }
if ($final_selection == $initial_selection) {
if ($goat == $initial_selection) {
$unswitched++;
} else {
$switched++;
@ -42,7 +44,7 @@ for (my $i = 0; $i < 100000000; $i++) {
# say "correct? " . ($result ? 'yes' : 'no');
if ($i % 10000 == 0) {
say "$i :: " . ($switched - $unswitched);
say "$switched, $unswitched ";
}
}


Loading…
Cancel
Save