Created
June 9, 2019 13:28
-
-
Save xbony2/b0381bde6b2da0f1156b0bb4fcddc680 to your computer and use it in GitHub Desktop.
This file contains 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
arr = [7600, 5900, 1400] | |
seats = 36 | |
total = 0.0 | |
arr.each { |e| total += e } | |
puts "Total: #{total}" | |
s_d = total / seats | |
puts "SD: #{s_d}" | |
puts | |
puts "State\tPopulation\tQ\tLQ\tApportionment" | |
arr.each do |v| | |
s_q = v / s_d | |
puts "#{arr.index(v)}\t#{v}\t#{s_q.truncate(3)}\t#{s_q.truncate}" | |
end | |
l_q_total = 0 | |
arr.each { |e| l_q_total += (e / s_d).truncate} | |
puts "Total\t#{total}\t#{seats}\t#{l_q_total}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment