in reply to Messing Around

I don't get it, it's a three liner with a bit (or byte) combining.. Or has it to be readable? :D
my @numbers; $numbers[ int(rand(54)) + 1 ]++ for 1 .. 10_000; print join ', ', ( map { "$_ ".($numbers[$_]||'0') } reverse sort { $n +umbers[ $a ] <=> $numbers[ $b ] } (1 .. 54) )[0..5];
Update: I f'd it up with rand and put a 53 where a 54 should be. Thanks to ikegami for catching that.

Ordinary morality is for ordinary people. -- Aleister Crowley

Replies are listed 'Best First'.
Re^2: Messing Around
by atcroft (Abbot) on Feb 22, 2005 at 23:35 UTC

    No, it's a command-line one-liner.... perl -e 'srand;push(@c,0)foreach(0..53);foreach(1..1e4){@d=(); foreach(0..53){$e{$_}=1;}foreach(0..5){$i=int(rand(54));while (!$e{$i}){$i=int(rand(54));} push(@d,$i);$e{$i}=0;} foreach(@d){$c[$_]++}}foreach(sort{$c[$b]<=>$c[$a]}0..$#c) {print $_+1," ",$c[$_],", ";}'

    It also prevents duplicates per drawing. Explaining how it works and where they got it is left as an exercise to the student (as this smells a bit like homework)....

    Update 22 Feb 2005: Fixed small typos, added a few spaces into code.

    Update 22 Feb 2005: The code above appears to run in just under 1.0s, according to time(1), and weighs in around 267c total (256c for the code).

Re^2: Messing Around
by ikegami (Patriarch) on Feb 22, 2005 at 23:17 UTC
    int(rand(53)) + 1 gives a number from 1 to 53. Did you mean int(rand(54)) + 1?
      Yep, you got me :D I have a version here which doesn't pick numbers twice, but it's still running.. I guess this is not for production,

      Ordinary morality is for ordinary people. -- Aleister Crowley