#!/usr/bin/perl my $wins = 0; my $lose = 0; my $goat; for (my $i=0;$i<1000000;$i++) { my $car = int rand(3); my $choice = int rand(3); do { $goat = int rand(3); } while (($goat != $car) && ($goat != $choice)); if ($choice != $car) {$wins++} else {$lose++}; } print "WINS = $wins!\nLOSE = $lose!\n";
takes about 10 wallclock seconds at my machine, while the original takes more than 70 seconds.
In reply to Re: Marilyn Vos Savant's Monty Hall problem
by Joost
in thread Marilyn Vos Savant's Monty Hall problem
by mutated
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |