|
|
@@ -0,0 +1,43 @@ |
|
|
|
# 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 |