From 9214483dd624bea9e64170da2aa5325bb6de1069 Mon Sep 17 00:00:00 2001 From: TiagoRG <35657250+TiagoRG@users.noreply.github.com> Date: Thu, 1 Dec 2022 22:45:37 +0000 Subject: [PATCH] extras/ex04 added --- 1ano/fp/extra1/ex04.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 1ano/fp/extra1/ex04.py diff --git a/1ano/fp/extra1/ex04.py b/1ano/fp/extra1/ex04.py new file mode 100644 index 0000000..9b24744 --- /dev/null +++ b/1ano/fp/extra1/ex04.py @@ -0,0 +1,17 @@ +# Not passing codecheck tests + +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