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;
}
}
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};
}
}
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];