Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Re: Filling buckets

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


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 20: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
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-03-28 17:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found