in reply to Marilyn Vos Savant's Monty Hall problem

Cool. One remark: using int rand() instead of your random() sub should make it more efficient, and IMHO more readable:

#!/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.

Replies are listed 'Best First'.
Re^2: Marilyn Vos Savant's Monty Hall problem
by mutated (Monk) on Aug 19, 2004 at 13:54 UTC
    Hey cool thanks!


    daN.