You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.4 KiB

  1. #!/usr/bin/env perl
  2. use strict;
  3. use warnings;
  4. use 5.10.0;
  5. # NOTE: we got the thing about the goat being the prize backwards
  6. # from how this is usually defined.
  7. # basic setup:
  8. # you get 3 doors
  9. # - initially, you pick a door at random
  10. # - second, the host eliminates one of the two remaining doors that you haven't picked
  11. # - now, you have the option to switch to the remaining door from the one you've already picked
  12. my ($switched, $unswitched) = (0, 0);
  13. my $doors = 3;
  14. for (my $i = 0; $i < 1000000; $i++) {
  15. my $goat = int(rand($doors));
  16. my $initial_selection = int(rand($doors));
  17. # my $host_eliminates = int(rand($doors));
  18. # until (($host_eliminates != $initial_selection) && ($host_eliminates != $goat)) {
  19. # $host_eliminates = int(rand($doors));
  20. # }
  21. # THIS IS OUR BUG (i kind of think)
  22. # my $final_selection = int(rand($doors));
  23. # until ($final_selection != $host_eliminates) {
  24. # $final_selection = int(rand($doors));
  25. # }
  26. if ($goat == $initial_selection) {
  27. $unswitched++;
  28. } else {
  29. $switched++;
  30. }
  31. # say "you pick: $initial_selection"; say "host eliminates: $host_eliminates";
  32. # say "goat is: $goat";
  33. # say "final selection is: $final_selection";
  34. # say "correct? " . ($result ? 'yes' : 'no');
  35. if ($i % 10000 == 0) {
  36. say "$switched, $unswitched ";
  37. }
  38. }
  39. say "switched from initial decision: $switched";
  40. say "unswitched from initial decision: $unswitched";