Skip to content

Instantly share code, notes, and snippets.

@xbony2
Created June 9, 2019 13:28
Show Gist options
  • Save xbony2/b0381bde6b2da0f1156b0bb4fcddc680 to your computer and use it in GitHub Desktop.
Save xbony2/b0381bde6b2da0f1156b0bb4fcddc680 to your computer and use it in GitHub Desktop.
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