Skip to content

dominicrutk/apportionment-calculator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Apportionment Calculator

This command line calculator can apportion seats based on the Huntington-Hill method (the method used by the U.S. House). It was inspired by this calculator from the University of Michigan, but it is designed to be more flexible by (a) not being restricted to U.S. states and (b) not being limited to 999 seats.

Usage

Currently, you must have Rust installed to run this tool (instructions here).

To run the calculator with 435 seats and the 2020 U.S. Census numbers, simply run:

cargo run

Of course, you could have Googled that information. You came here for customization.

To adjust the state names, add/remove states, or adjust populations, create a new tab-separated value (tsv) file. In it, each row should contain the state name, a tab character, and the state population without commas. A full example of the 2020 U.S. Census is available in a file named us2020.tsv under the data/us directory.

Once you have a file with state names and populations, simply pass it as the --input (-i) argument to the cargo run command.

cargo run -- -i path_to_file.tsv

If you want to adjust the total number of seats, pass the desired number as the --seats (-s) argument.

cargo run -- -s 1000

Alternatively, use the -C flag to calculate the number of seats using the cube root rule. For even more customization, pass a multiplier to the total number of seats produced by the cube root rule as the -c argument.

cargo run -- -C # Equivalent to cargo run -- -c 1
cargo run -- -c 2

The Wyoming rule is also an option. Use the -W flag to calculate the number of seats using the Wyoming rule where the smallest state gets 1 seat. For even more customization, pass the desired number of seats for the smallest state as the -w argument.

cargo run -- -W # Equivalent to cargo run -- -w 1
cargo run -- -w 10

By default, the tab-separated results will appear in the command line. If you want to specify an output file for the results, pass it as the --output (-o) argument.

cargo run -- -o path_to_file.tsv

You can specify these arguments in any order, and each argument is optional.

  • The input file will default to the 2020 U.S. Census data (data/us2020.tsv).
  • The number of seats will default to 435.
  • The output will default to the command line.

Data

The data directory currently contains all U.S. Census data since 1990. Contributions of older data or data from other countries would be much appreciated. Simply submit a pull request.

About

Flexible command line implementation of the Huntington-Hill apportionment method

Topics

Resources

License

Stars

Watchers

Forks

Languages