I was in the voting booth today and I noticed that the percentages for the 90 votes only added up to 96%.
If we have a voting booth, shouldn't the %'s = 100? I took this as a challenge
to write a better voting booth rounder.
--eric
#!/usr/bin/perl -w
use strict;
my %votes = (
plane => 5,
cbn => 10,
wall => 2,
pass => 11,
shirt => 5,
vison => 7,
mind => 26,
name => 10,
tooth => 14,
);
my $total;
for (values %votes){
$total += $_;
}
my %pcts;
my $diff = 100;
foreach my $vote (keys %votes){
my $pct = $votes{$vote}/$total * 100;
$diff -= int($pct);
$pcts{$vote} = $pct;
}
my $format = "%-12s" x 3;
my @titles = qw(ANSWER VOTES/PCT RAW-PCT);
printf("$format\n", @titles);
my $new_total = 0;
foreach my $answ (sort { ($pcts{$b} - int($pcts{$b}))
<=>
($pcts{$a} - int($pcts{$a}))
} keys %pcts ){
my $round = int($pcts{$answ});
$round += 1 if $diff-- > 0;
printf("$format\n",$answ,"$votes{$answ}/$round%",
$pcts{$answ});
$new_total += $round;
}
print "\n\tNew % Total: $new_total%\n";