ika #5225(2008/01/08 09:25 GMT) [ D ] Rating0/0=0.00
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
private import std.stdio; uint[] dhondt(uint[] votes, uint limit) { auto seats = new uint[votes.length]; foreach(_; 0 .. limit) { auto quotients = new real[votes.length]; foreach(i, ref e; quotients) { e = votes[i] / (seats[i] + 1.0); } find_largest: foreach(i, e; quotients) { foreach(f; quotients[i .. $]) { if(f > e) continue find_largest; } seats[i]++; break; } } return seats; } void main() { writeln([123, 4, 56, 78].dhondt(100)); // [48 1 21 30] }
Rating0/0=0.00-0+
[ reply ]
ika
#5225()
[
D
]
Rating0/0=0.00
Rating0/0=0.00-0+
[ reply ]