Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Re: Filling buckets

by Fastolfe (Vicar)
on Jan 03, 2001 at 03:42 UTC ( [id://49462]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Re: Filling buckets
in thread Filling buckets

Here's a nicer solution (IMO) using splice:
sub split_into { my $howmany = shift; my @from = reverse @_; my @buckets; unshift(@buckets, [ reverse splice(@from, 0, @from / $howmany--) ]) + while $howmany; @buckets; }
Or, dropping @buckets at the expense of readability (and perhaps efficiency):
sub split_into { my $howmany = shift; my @from = reverse @_; reverse map { [ reverse splice(@from, 0, @from / $_) ] } reverse 1 .. $howmany; }

Replies are listed 'Best First'.
Re: Re: Re: Filling buckets
by t'mo (Pilgrim) on Jan 03, 2001 at 15:02 UTC

    ...but that second example just looks good...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://49462]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.