in reply to Re: How to Group List Items?
in thread How to Group List Items?

Sorry - I'm looking to have 6 groups, no fewer.

I'd like the groups scored by how many items they contain different from the ideal (the lower, the better):

my $ideal_avg_per_group = @list / 6; # your solution my $solution = [ [1 1 1 2 3], [4 4 4 5 5], [6 6 6 7 7], [8 8 8] ]; my $this_score = 0; for (@$solution) { my $num_items = @$_; $this_score += abs($ideal_avg_per_group - $num_items); }
Also, it's fine to assume that there are more than 6 unique values in the list. Otherwise, it's obviously very easy.

Thanks!

Replies are listed 'Best First'.
Re^3: How to Group List Items?
by waswas-fng (Curate) on Jul 26, 2007 at 21:18 UTC
    I still do not see where you are defining the concept of $ideal_avg_per_group. You can look at Algorithm::Bucketizer to see if that gets you anywhere -- but without a better definition of the problem it is anyones guess what a solution really is.


    -Waswas
      Look for where he assigns it.