chiark / gitweb /
compute-scottish-stv: nicer output
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 21 Aug 2016 21:07:12 +0000 (22:07 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 21 Aug 2016 21:07:12 +0000 (22:07 +0100)
compute-scottish-stv

index e09f1ebcefb4430d7b8299afa0c27b8dcbd4d3e5..528cc5f0891a1556a26ed89c96547406122e1dba 100755 (executable)
@@ -31,6 +31,7 @@ our %cands;
 our $stage=0;
 our $quota;
 our %tie;
+our @elected;
 
 our $DIGS = 5;
 our $F = (new Math::BigRat 10)->bpow($DIGS);
@@ -288,6 +289,7 @@ sub elect_core ($) {
     my ($c) = @_;
     prf "*** ELECT %s \`%s' ***\n", $c->{Cand}, $c->{Desc};
     $c->{NonCont} = 'Elected';
+    push @elected, $c;
 }
 
 $stage = 0;
@@ -297,8 +299,12 @@ for (;;) {
 
     sortballots @allvotes if $stage == 1;
 
-    my $seats_remain = $seats
-       - grep { ($_->{NonCont} // '') eq 'Elected' } values %cands;
+    my $seats_remain = $seats - @elected;
+
+    prf "seats remaining %d\n", $seats_remain;
+
+    last unless $seats_remain;
+
     if (continuing() <= $seats_remain) {
        foreach my $c (continuing()) {
            prf "electing %s to fill remaining place(s)\n", $c->{Cand};
@@ -375,4 +381,11 @@ for (;;) {
     die;
 }
 
-print "done.\n"; 
+print "Winners:\n"; 
+
+foreach my $i (0..$#elected) {
+    my $c = $elected[$i];
+    printf " %3d. %-10s %s\n", $i+1, $c->{Cand}, $c->{Desc};
+}
+
+print "done.\n";