in reply to Re: How to Group List Items?
in thread How to Group List Items?
I'd like the groups scored by how many items they contain different from the ideal (the lower, the better):
Also, it's fine to assume that there are more than 6 unique values in the list. Otherwise, it's obviously very easy.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); }
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 | |
by ysth (Canon) on Jul 27, 2007 at 01:45 UTC |