in reply to Finding the best option...

It doesn't (yet) have an algorithm except "brute force" and "random", but Algorithm::Bucketizer provides a framework for solving tasks like these:
my @values = (10,40,30,14,50,29,59,20,59,20,10,1,3,5,2,4); use Algorithm::Bucketizer; # Create a bucketizer my $bucketizer = Algorithm::Bucketizer->new(bucketsize => 291); for my $value (@values) { # Add items to it $bucketizer->add_item($value, $value); } $bucketizer->optimize(maxrounds => 1000, algorithm => "brute_force"); for my $bucket ($bucketizer->buckets()) { my @items = $bucket->items(); print $bucket->level(), ": @items\n"; }

1000 Rounds:

286: 4 2 5 3 1 10 20 59 20 59 29 50 14 10 70: 30 40

10,000 Rounds:

286: 4 2 5 3 1 10 20 59 20 59 29 50 14 10 70: 30 40
If you find a usable algorithm, it can be plugged into Algorithm::Bucketizer as a standard choice.