It's time... to count the votes!
Today there are local elections in my entire country. Here, the number of seats for each party is decided using the D'Hondt method. Your goal is to implement a program or function that will decide how many seats each party gets, in the shortest amount of bytes.
For this method there are a fixed number of seats to distribute, and it's done like so:
- Every party is assigned a variable number, which starts at the number of votes it got.
- Then the first seat is given to the party who has the biggest value in their variable and then that value for that party becomes their total number of votes divided by
1+seats, rounded down, where
seatsis the number of seats it already has (so after getting the first, their votes are divided by 2, and by 3 after getting the second seat).
- After that the parties votes are compared again. The process continues until all the seats have been assigned.
If the highest number is a tie between two or more parties, it is resolved randomly (It has to be random, it can't just be the first of the two in the list).
You will receive a number
N, which will indicate the number of seats available, and a list of the votes each party received, in whatever format you prefer. Example:
You should output a list of the seats each party got. In the example above it would be something like
They should be in the same order as the parties in the input.
5 3,6,1 outputs: 2,3,0
135 1116259,498124,524707,471681,359705,275007,126435 outputs: 45,20,21,19,14,11,5
-20% bonus if take the parties name as input and give them in the output, like for example:
25 cio:12984,pcc:7716,irc:13009,icb:4045,cub:1741,bb:1013 outputs cio:8 pcc:5 irc:9 icb:2 cub:1 bb:0