Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: Proving Veritasiums riddle using Perl

by cavac (Prior)
on Apr 30, 2025 at 20:55 UTC ( [id://11164872]=note: print w/replies, xml ) Need Help??


in reply to Re: Proving Veritasiums riddle using Perl
in thread Proving Veritasiums riddle using Perl

I think setting up the boxes might be easier and faster with something like Array::Shuffle.

Yes. And it would be way faster. My randomizer as probably the least efficient version possible.

The other variant would probably to just generate the array of numbers, then randomly select and splice.

I just wanted to do a qick proof of concept without looking up anything and hand-rolled algos (without modules) so i can easily play with every part to see what happens. I do Perl 40 hours a week at work¹, this one was a just-for-fun little home project without any code quality and/or maintainability requirements ;-)


¹ all to do with Point-of-Sales stuff and financial data. I nearly never get to use rand() based stuff, so i'm a bit rusty in that regard

PerlMonks XP is useless? Not anymore: XPD - Do more with your PerlMonks XP
Also check out my sisters artwork and my weekly webcomics
  • Comment on Re^2: Proving Veritasiums riddle using Perl

Replies are listed 'Best First'.
Re^3: Proving Veritasiums riddle using Perl
by pfaut (Priest) on Apr 30, 2025 at 21:34 UTC

    Cool program. It's much faster using a shuffle.

    Your code:

    % time perl prisoners-orig.pl == SIMULATION 9900 of 10000 == Success: 3085 Fail: 6915 Fail rate: 69.15% perl prisoners-orig.pl 13.09s user 0.01s system 99% cpu 13.101 total

    Modified to use Array::Shuffle:

    % time perl prisoners.pl == SIMULATION 9900 of 10000 == Success: 3175 Fail: 6825 Fail rate: 68.25% perl prisoners.pl 0.71s user 0.00s system 99% cpu 0.716 total

    Diff:

    90% of every Perl application is already written.
    dragonchild

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11164872]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2025-06-16 02:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.