X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=blobdiff_plain;f=compute-scottish-stv;h=4715808de5057be8fcc5bb30f59ca19c3080df58;hb=2251d06cbf7d16682040782d415c371a43fdf275;hp=6fde10308b409753d9f877e1df709300d2558fa3;hpb=a4f2fc687bb9e16c33a59619acafe2cc21833ee1;p=appendix-a6.git diff --git a/compute-scottish-stv b/compute-scottish-stv index 6fde103..4715808 100755 --- a/compute-scottish-stv +++ b/compute-scottish-stv @@ -155,9 +155,12 @@ sub countballots () { next if $c->{NonCont}; $c->{Total} = 0; $c->{Total} += $_->{Weight} foreach @{ $c->{Votes} }; - prf "candidate %-10s: %10s votes\n", $cand, $c->{Total}; $c->{History}[$stage-1] = $c->{Total}; } + + foreach my $c (reverse sort total_history_cmp values %cands) { + prf "candidate %-10s: %10s votes\n", $c->{Cand}, $c->{Total}; + } } sub computequota () { @@ -244,15 +247,13 @@ sub elect_core ($) { $c->{NonCont} = 'Elected'; } -$stage = 1; - -sortballots @allvotes; -countballots(); -computequota(); +$stage = 0; for (;;) { $stage++; + sortballots @allvotes if $stage == 1; + my $seats_remain = $seats - grep { ($_->{NonCont} // '') eq 'Elected' } values %cands; if (continuing() <= $seats_remain) { @@ -265,6 +266,8 @@ for (;;) { countballots(); + computequota if $stage == 1; + my $c = select_best_worst sub { $_->{Total} >= $quota }, sub { $_ > $quota },