in reply to Proving Veritasiums riddle using Perl

Very interesting problem and very interesting algorithm. Statistics are very often counter-intuitive.

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

90% of every Perl application is already written.
dragonchild
  • Comment on Re: Proving Veritasiums riddle using Perl

Replies are listed 'Best First'.
Re^2: Proving Veritasiums riddle using Perl
by cavac (Prior) on Apr 30, 2025 at 20:55 UTC

    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

      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