From: Ian Jackson Date: Tue, 23 Aug 2016 12:45:45 +0000 (+0100) Subject: compute-scottish-stv: new --for-compare option X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=appendix-a6.git;a=commitdiff_plain;h=af19a4306f157650f182d15cf4e02325f372b2d7 compute-scottish-stv: new --for-compare option --- diff --git a/compute-scottish-stv b/compute-scottish-stv index a7fb378..12645fd 100755 --- a/compute-scottish-stv +++ b/compute-scottish-stv @@ -70,6 +70,7 @@ sub unkopt ($$) { } my $display_cmp = \&total_history_cmp; +my $for_compare = 0; while (@ARGV && $ARGV[0] =~ m/^\-/) { $_ = shift @ARGV; @@ -77,6 +78,9 @@ while (@ARGV && $ARGV[0] =~ m/^\-/) { last; } elsif (m/^--sort=alpha$/) { $display_cmp = sub { $b->{Cand} cmp $a->{Cand} }; + } elsif (m/^--for-compare$/) { + $for_compare = 1; + unshift @ARGV, '--sort=alpha'; } else { die; } @@ -327,6 +331,7 @@ for (;;) { prf "electing %s to fill remaining place(s)\n", $c->{Cand}; elect_core $c; } + countballots() if $for_compare; last; } @@ -402,9 +407,15 @@ for (;;) { print "Winners:\n"; -foreach my $i (0..$#elected) { - my $c = $elected[$i]; - printf " %3d. %-10s %s\n", $i+1, $c->{Cand}, $c->{Desc}; +if ($for_compare) { + foreach my $c (sort { $a->{Cand} cmp $b->{Cand} } @elected) { + printf " %s\n", $c->{Cand}; + } +} else { + foreach my $i (0..$#elected) { + my $c = $elected[$i]; + printf " %3d. %-10s %s\n", $i+1, $c->{Cand}, $c->{Desc}; + } } print "done.\n";