in reply to Re^2: Divide array of integers into most similar value halves
in thread Divide array of integers into most similar value halves
Thanks. That is indeed a bug. The (lightly tested) fix is to change the last line of the sub to:
return \@best, [ grep{ !exists $seen{ $_ } or !$seen{ $_ }-- } @$a +Ref ];
Basically, because the sub only stores one best partition, when it runs out of iterations, it needs to filter the input array to generate teh other half. The filter was a sloppy variation on a theme that works for other purposes but not this. I think the above corrects it, but I will need to give more thought once my brain has awoken.
|
|---|