in reply to Holiday parcel puzzle
use strict; use warnings; use 5.010; my $max = 1000; my %wins; for ( 1 .. $max ) { my @parcels = ( 1, 0, 0 ); $wins{hold} += splice @parcels, rand @parcels, 1; $wins{switch} += $parcels[0]; } say "$_:\t$wins{$_}" for keys %wins;
Update: Added spoiler tags
Update 2: Looking now at the OP's much more verbose code, I wonder if mine is not too concise, especially if the aim is to convince someone who doubts the actual odds.
Anyway, it was enough to convince me! :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Holiday parcel puzzle
by cavac (Prior) on Dec 22, 2011 at 20:17 UTC | |
by Not_a_Number (Prior) on Dec 22, 2011 at 20:34 UTC | |
by cavac (Prior) on Dec 22, 2011 at 20:52 UTC | |
|
Re^2: Holiday parcel puzzle
by JavaFan (Canon) on Dec 22, 2011 at 22:33 UTC |