From: Ian Jackson Date: Mon, 1 Aug 2016 12:51:53 +0000 (+0100) Subject: stv: wip, before delay transfer X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=appendix-a6.git;a=commitdiff_plain;h=b673f3ba34855765aca513ee45b84a918eaad099 stv: wip, before delay transfer --- diff --git a/stv b/stv index b2ae674..9e0acee 100755 --- a/stv +++ b/stv @@ -20,12 +20,13 @@ our $places = shift @ARGV; die unless $places eq ($places + 0); while (<>) { - m/^(\w+) ([A-Z]+)$/ or die; + next if m/^\w+$/; + m/^(\w+) ([A-Z]+)$/ or die "$_ ?"; my $prefs = $1; my $vote = { Voter => $1, Weight => 1.0, - Prefs => (split //, $prefs), + Prefs => [ split //, $prefs ], }; push @allvotes, $vote; } @@ -63,7 +64,7 @@ for (;;) { } foreach my $firstpref (sort keys %sorted) { foreach my $vote (@{ $sorted{$firstpref}{Votes} }) { - votelog $vote, "counted $vote->{Weight] for $firstpref"; + votelog $vote, "counted $vote->{Weight} for $firstpref"; $sorted{$firstpref}{Total} += $vote->{Weight}; } } @@ -86,7 +87,7 @@ for (;;) { printf "\nquota = %10s\n", pr $quota; my $topfirst = $sorted[0]; - my $topvoters = $sorted{ }{Weight}; + my $topvoters = $sorted{$topfirst}{Weight}; my $surplus = $topvoters - $quota; if ($surplus >= 0) { printf "%10s ELECTED\n", $sorted[0];