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...