+ for (;;) {
+ last unless @sorted;
+
+ my @elim = equalpiles 'elim?', reverse @sorted;
+ my $elimvote = sum map { $_->{Total} } @elim;
+ my $elimvotetotal = $elimvote * scalar @elim;
+
+ if (@surpluses and $elimvotetotal > $deferredsurplus) {
+ printf "no-elim, un-defer\n";
+ last;
+ }
+
+ if ((scalar keys %continuing) - (scalar @elim) < $placesremain) {
+ # eliminate only one then, and try again
+ printf "elim-tie!\n";
+ @elim = historically_prefer -1, @elim;
+ }
+
+ foreach my $s (@elim) {
+ my $c = $s->{Cand};
+ printf "%7s %10s\n", 'ELIM', $c;
+ my $votes = $s->{Votes};
+ votelog $_, "failed to stop $c elimination" foreach @$votes;
+ delete %continuing{$c};
+ delete %sorted{$c};
+ push @unsorted, @$votes;
+ }
+
+ $sort_update->();
+ $need_to_transfer_surplus = 0;
+ }