Yet another n-buckets routine:
#!/usr/bin/perl -w use strict; my @array = ('a' .. 'z'); my @buckets = n_buckets(3, @array); foreach my $aref (@buckets) { print scalar @$aref, ":@$aref\n"; } # n_buckets(n, list) sub n_buckets { my @buckets = ([]) x shift; my @list = @_; my $mod = @list % @buckets; my $inc = int(@list / @buckets); map{ [splice @list, 0, $inc + (--$mod >= 0)] } 0 .. $#buckets; } __END__
In reply to Re: Filling buckets
by danger
in thread Filling buckets
by meonkeys
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |