Created
May 26, 2014 13:45
-
-
Save adrianshort/9ec176bfdeff667e02db to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# D'Hondt method calculations | |
# https://en.wikipedia.org/wiki/D'Hondt_method | |
# By Adrian Short (@adrianshort) 26 May 2014 | |
# European Parliament election, London region, 22 May 2014 | |
@parties = { | |
'4 Freedoms Party (UK EPP)' => 28014, | |
'An Independence from Europe' => 26675, | |
'Animal Welfare Party' => 21092, | |
'British National Party' => 19246, | |
'Christian Peoples Alliance' => 23702, | |
'Communities United Party' => 6951, | |
'Conservative Party' => 495639, | |
'English Democrats' => 10142, | |
'Europeans Party' => 10712, | |
'Green Party' => 196419, | |
'Harmony Party' => 1985, | |
'Labour Party' => 806959, | |
'Liberal Democrats' => 148013, | |
'National Health Action Party' => 23253, | |
'National Liberal Party True Liberalism' => 6736, | |
'NO2EU' => 3804, | |
'UK Independence Party (UKIP)' => 371133 | |
} | |
@seats = 8 # Total number of seats to be elected in this district | |
@averages = [] | |
@parties.each do |party| | |
(1..@seats).each do |denominator| | |
@averages << [ party[0], party[1] / denominator ] | |
end | |
end | |
@winners = @averages.sort { |a,b| b[1] <=> a[1] }[0..@seats - 1] | |
puts "Place. Party" | |
(1..@seats).each do |place| | |
puts "%d. %s" % [ place, @winners[place - 1][0]] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
And the output:
Place. Party