in reply to Re^8: Marilyn Vos Savant's Monty Hall problem
in thread Marilyn Vos Savant's Monty Hall problem

I don't think that there is a good short way to state it.

Perhaps the best way is to be verbose as in:

my @available; if ( $door[ $choice ] eq 'car' ) { # Can't beat him yet @available = grep { $choice != $_ } 0 .. 2; } else { # Make him lose! @available = grep { $doors[ $_ ] eq 'car' } 0 .. 2; }

Replies are listed 'Best First'.
Re^10: Marilyn Vos Savant's Monty Hall problem
by BrowserUk (Patriarch) on Aug 23, 2004 at 23:28 UTC

    How about ?

    my $MontysChoice; if( $doors[ choice ] ne 'car' ) { $MontysChoice = grep{ $doors[ $_ ] eq 'car' } 0 .. 2; } else { $MontysChoice = ( grep{ $_ != $choice } 0 .. 2 )[ rand 2 ]; }

    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    "Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon