A friend of mine wanted to show that under reasonable assumptions Clinton still would've lost the election even if it were a head-to-head contest. In other words, third party candidates didn't cost Clinton the election. All he really wanted to find out is what percentage of Johnson voters had to vote Clinton in order for Clinton to win. This is pretty easy to do; I could probably solve this in less than 5 minutes in Excel. However, he wrote the code in Mathematica, and so I decided to do it in Rust.

I used two crates, csv and serde. Csv is needed to read the CSV election data, and serde to put the data into a struct so that it is nicely formatted with names and everything. The code should be pretty self-explanatory, as it is not very complex. Take note of the error handling, which I tried to do properly even though there wasn't any real need for it here.

Anyways, here is the code.