chiark
/
gitweb
/
~ian
/
appendix-a6.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
4642960
)
compute-scottish-stv: nicer output
author
Ian Jackson
<ijackson@chiark.greenend.org.uk>
Sun, 21 Aug 2016 21:07:12 +0000
(22:07 +0100)
committer
Ian Jackson
<ijackson@chiark.greenend.org.uk>
Sun, 21 Aug 2016 21:07:12 +0000
(22:07 +0100)
compute-scottish-stv
patch
|
blob
|
history
diff --git
a/compute-scottish-stv
b/compute-scottish-stv
index e09f1ebcefb4430d7b8299afa0c27b8dcbd4d3e5..528cc5f0891a1556a26ed89c96547406122e1dba 100755
(executable)
--- a/
compute-scottish-stv
+++ b/
compute-scottish-stv
@@
-31,6
+31,7
@@
our %cands;
our $stage=0;
our $quota;
our %tie;
our $stage=0;
our $quota;
our %tie;
+our @elected;
our $DIGS = 5;
our $F = (new Math::BigRat 10)->bpow($DIGS);
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';
my ($c) = @_;
prf "*** ELECT %s \`%s' ***\n", $c->{Cand}, $c->{Desc};
$c->{NonCont} = 'Elected';
+ push @elected, $c;
}
$stage = 0;
}
$stage = 0;
@@
-297,8
+299,12
@@
for (;;) {
sortballots @allvotes if $stage == 1;
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};
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;
}
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";