not really known
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.4 KiB

  1. # D'Hondt method calculations
  2. # https://en.wikipedia.org/wiki/D'Hondt_method
  3. # By Adrian Short (@adrianshort) 26 May 2014
  4. # European Parliament election, London region, 22 May 2014
  5. @parties = {
  6. '4 Freedoms Party (UK EPP)' => 28014,
  7. 'An Independence from Europe' => 26675,
  8. 'Animal Welfare Party' => 21092,
  9. 'British National Party' => 19246,
  10. 'Christian Peoples Alliance' => 23702,
  11. 'Communities United Party' => 6951,
  12. 'Conservative Party' => 495639,
  13. 'English Democrats' => 10142,
  14. 'Europeans Party' => 10712,
  15. 'Green Party' => 196419,
  16. 'Harmony Party' => 1985,
  17. 'Labour Party' => 806959,
  18. 'Liberal Democrats' => 148013,
  19. 'National Health Action Party' => 23253,
  20. 'National Liberal Party True Liberalism' => 6736,
  21. 'NO2EU' => 3804,
  22. 'UK Independence Party (UKIP)' => 371133
  23. }
  24. @seats = 8 # Total number of seats to be elected in this district
  25. @averages = []
  26. @parties.each do |party|
  27. (1..@seats).each do |denominator|
  28. @averages << [ party[0], party[1] / denominator ]
  29. end
  30. end
  31. @winners = @averages.sort { |a,b| b[1] <=> a[1] }[0..@seats - 1]
  32. puts "Place. Party"
  33. (1..@seats).each do |place|
  34. puts "%d. %s" % [ place, @winners[place - 1][0]]
  35. end