chiark / gitweb /
stv: wip, before delay transfer
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 1 Aug 2016 12:51:53 +0000 (13:51 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 1 Aug 2016 12:51:53 +0000 (13:51 +0100)
stv

diff --git a/stv b/stv
index b2ae674f18085097c510c88514c9e54d7b9c300b..9e0aceee2dd826ed83a2187795b809d2bb0d17f1 100755 (executable)
--- 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];