#!/usr/bin/perl -w
@V = (9600, 375, 3000, 5000, 1000, 200);
$seats = 100;
@s = (0) x scalar @V;
for $i (1..$seats) {
$max=0;
for $j (0..-1+scalar @V) {
$r[$j] = $V[$j]/(2*$s[$j]+1);
}
for $j (0..-1+scalar @V) {
if ($r[$j] > $max) {
$max = $r[$j];
$seat = $j;
}
}
$s[$seat]++;
$stat[$seat]++;
print "El escaño $i va para el partido $seat\n";
}
for $j (0 .. $#V){
print "Partido $j -> $stat[$j] escaños\n";
}
__END__
From the wikipedia:
After all the votes have been tallied, successive quotients are
calculated for each party. The formula for the quotient is[1]
quot = V 2 s + 1 {\displaystyle {\text{quot}}={\frac
{V}{2s+1}}} {\displaystyle {\text{quot}}={\frac {V}{2s+1}}}
where:
V is the total number of votes that party received, and
s is the number of seats that have been allocated so far to
that party, initially 0 for all parties.
Whichever party has the highest quotient gets the next seat allocated,
and their quotient is recalculated. The process is repeated until all
seats have been allocated.
The Webster/Sainte-Laguë method does not ensure that a party receiving
more than half the votes will win at least half the seats; nor does
its modified form.[5] For example, with seven seats available and the
votes split 53,000, 24,000 and 23,000, the allocation would be three,
two and two seats respectively: