- if ($nelect) {
- my $elect;
- if ($nelect > 1) {
- my @all = @maybe_elect[0 .. $nelect-1];
- my $elect = $tie{"@all"}{Win};
- die "need tie break, want winner from @all" unless defined $win;
- prf "electing %s due to tie break amongst %s\n",
- $elect, "@all";
- } else {
- $elect = $maybe_elect[0];
- prf "electing %s\n";
+ if ($nequal > 1 && !$wanttiebreak->($maybe[0]{Total})) {
+ # ... if equal for election we can do them one by one, since
+ # order does not matter (SLGEO 49 talks about `two or more
+ # ... exceeds').
+ $nequal = 1;
+ }
+
+ my $selectcand;
+ if ($nequal > 1) {
+ my @all = map { $_->{Cand} } @maybe[0 .. $nequal-1];
+ my $tiekey = $signum > 0 ? 'Win' : 'Lose';
+ $selectcand = $tie{"@all"}{$tiekey};
+ die "need tie break, want $tiekey from @all"
+ unless defined $selectcand;
+ prf "$what %s due to tie break amongst %s\n",
+ $selectcand, "@all";
+ } else {
+ $selectcand = $maybe[0]{Cand};
+ prf "$what %s\n", $selectcand;
+ }
+
+ return $cands{$selectcand};
+}
+
+sub elect_core ($) {
+ my ($c) = @_;
+ prf "*** ELECT %s \`%s' ***\n", $c->{Cand}, $c->{Desc};
+ $c->{NonCont} = 'Elected';
+}
+
+$stage = 0;
+
+for (;;) {
+ $stage++;
+
+ sortballots @allvotes if $stage == 1;
+
+ my $seats_remain = $seats
+ - grep { ($_->{NonCont} // '') eq 'Elected' } values %cands;
+ if (continuing() <= $seats_remain) {
+ foreach my $c (continuing()) {
+ prf "electing %s to fill remaining place(s)\n", $c->{Cand};
+ elect_core $c;