Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: Holiday parcel puzzle

by Not_a_Number (Prior)
on Dec 22, 2011 at 20:12 UTC ( #944838=note: print w/replies, xml ) Need Help??

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 (Deacon) on Dec 22, 2011 at 20:17 UTC

    Nice one. Actually, way nicer than mine.

    BREW /very/strong/coffee HTTP/1.1
    418 I'm a teapot

      So do I win the 1000XP?


        I i could give them to you, i probably would.

        But i'm just a humble Pilgrim, working in the Department Of Bugsniffing. My hope is, that, one day, i'll be promoted to Friar. If i'm very lucky, i might even get my own desk.

        BREW /very/strong/coffee HTTP/1.1
        418 I'm a teapot
Re^2: Holiday parcel puzzle
by JavaFan (Canon) on Dec 22, 2011 at 22:33 UTC
    The problem with your "concise" solution is that it's unclear whether your program matches the problem description. If you don't care about the latter, here's an even more concise one:
    use 5.010; say "Please wait while I run a simulation ...."; sleep 5; say "Elves have wrapped a billion parcels, calling FedEx ...."; sleep 10; say "Not switching wins 33.3% of the time"; say "Switching wins 66.7% of the time";

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://944838]
[Corion]: Meh. My bank removed (part of) their CSV download facilities. Now I will either have to implement a full scraper or automate the download using the HBCI interface instead (or just get a new account elsewhere...)
[Corion]: On the upside, I spend a lot of time thinking this weekend about how to actually implement rate limiting for futures, and if things work out, maybe even loading a configuration from an external file makes sense
[Corion]: I've also found some interesting invariants that I have to think/write about more. A simple rate limiter will never change the order of the input, while a limiter that allows for parallel execution will change the order. But my API currently allows for bo
[Corion]: ... for both, and I'm not sure if I want to add the cruft from the parallel API (a token that you need to hold on to while you hold the lock) to the rate limiting API too, to allow seamless up/downgrades, or not.
[Corion]: Also, rate limiting will look great with await: my $token = await $limiter-> limit($hostname); instead of my $f = $limiter->limit( $hostname )->then(sub { my( $token)=@_; ... });

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2017-10-23 08:21 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (277 votes). Check out past polls.