Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Seek one liner for distributing an integer

by ikegami (Patriarch)
on Sep 22, 2004 at 05:15 UTC ( [id://392841]=note: print w/replies, xml ) Need Help??


in reply to Seek one liner for distributing an integer

$result{$array[$num%@array]}++ while ($num--);

Replies are listed 'Best First'.
Re^2: Seek one liner for distributing an integer
by ikegami (Patriarch) on Sep 22, 2004 at 05:49 UTC

    or if you want something ugly:

    %result = map{pop@array,length}('1'x$num)=~/^@{['(.*)'.'(\1.?)'x$#array]}$/;

    Apparently, map + regexps can do anything! ☺

    Non-destructive:

    %result = map{$array[$i++],length}('1'x$num)=~/^@{['(.*)'.'(\1.?)'x$#array]}$/;
      Apparently, map + regexps can do anything!
      I'm pretty sure perl's flavor of regular expressions are turing complete, so you could do it all without the map. (I guess that would make them trans-regular expressions. Anyone got a better name?)


      -- All code is 100% tested and functional unless otherwise noted.
        Is "I'm pretty sure perl's flavor of regular expressions are turing complete" a challenge? :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (2)
As of 2024-04-26 05:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found