uaveiro-leci/1ano/1semestre/fp/extra1/ex04.py

18 lines
633 B
Python
Raw Permalink Normal View History

2023-01-30 16:48:43 +00:00
# Not passing codecheck tests although not sure why :skull:
2022-12-01 22:45:37 +00:00
def hondt(votes, numseats):
v = [vote for vote in votes]
seats = [0] * len(votes)
for i in range(numseats):
maxvotes = max(votes)
maxindex = votes.index(maxvotes)
maxvotes2 = max(votes[maxindex:])
maxindex2 = votes.index(maxvotes2)
if (maxvotes == maxvotes2) and (v[maxindex] < v[maxindex2]):
seats[maxindex2] += 1
votes[maxindex2] = maxvotes2 / (seats[maxindex2] + 1)
else:
seats[maxindex] += 1
votes[maxindex] = maxvotes / (seats[maxindex] + 1)
return seats