/**
* Maximum remainder allocationAlgorithm
* @ Author Xhan
*{ @ Link = Http://en.wikipedia.org/wiki/Largest_remainder_method }
*/
Public Class Sharecalculator {
Public Static Double [] Calculate ( Double [] Votes, Double Totalseats ){
Double [] Seats = New Double [Votes. Length];
Double [] Reminders = New Double [Votes. Length];
Double Totalvotes = 0;
For ( Double Vote: votes ){
Totalvotes + = vote;
}
Double Harequota = totalvotes/totalseats;
Double Allocatedseats = 0;
For ( Int I = 0; I <votes. length; I ++ ){
Double Votedivharequota = votes [I]/harequota;
Seats [I] = math. Floor (votedivharequota );
Reminders [I] = votedivharequota-seats [I];
Allocatedseats + = seats [I];
}
Double Leftseats = totalseats-allocatedseats;
// Allocate left seats to party with largest reminder
For ( Int I = 0; I <leftseats; I ++ ){
Double Max = 0;
Int Maxindex = 0;
For ( Int J = 0; j <reminders. length; j ++ ){
If (Reminders [J]> MAX ){
Max = reminders [J];
Maxindex = J;
}
}
Seats [maxindex] + = 1;
Reminders [maxindex] = 0;
}
Return Seats;
}
}