Import 2016 Electoral Vote Data
Import 2016 Electoral Vote Data
In[]:=
data=Import["http://www.infoplease.com/us/government/electoral-college-votes-state-elections.html","Data"];
In[]:=
$electoralVotes=Rule@@@Extract[data,Most[Most[First[Position[data,"Alabama"]]]]]
Out[]=
{Alabama9,Alaska3,Arizona11,Arkansas6,California55,Colorado9,Connecticut7,Delaware3,District of Columbia3,Florida29,Georgia16,Hawaii4,Idaho4,Illinois20,Indiana11,Iowa6,Kansas6,Kentucky8,Louisiana8,Maine4,Maryland10,Massachusetts11,Michigan16,Minnesota10,Mississippi6,Missouri10,Montana3,Nebraska5,Nevada6,New Hampshire4,New Jersey14,New Mexico5,New York29,North Carolina15,North Dakota3,Ohio18,Oklahoma7,Oregon7,Pennsylvania20,Rhode Island4,South Carolina9,South Dakota3,Tennessee11,Texas38,Utah6,Vermont3,Virginia13,Washington12,West Virginia5,Wisconsin10,Wyoming3}
In[]:=
CloudPut[$electoralVotes,FileNameJoin[{$CloudRootDirectory,"elections-2016","electoral-votes.m"}],Permissions"Public"]
In[]:=
$states=Keys[$electoralVotes]
Out[]=
{Alabama,Alaska,Arizona,Arkansas,California,Colorado,Connecticut,Delaware,District of Columbia,Florida,Georgia,Hawaii,Idaho,Illinois,Indiana,Iowa,Kansas,Kentucky,Louisiana,Maine,Maryland,Massachusetts,Michigan,Minnesota,Mississippi,Missouri,Montana,Nebraska,Nevada,New Hampshire,New Jersey,New Mexico,New York,North Carolina,North Dakota,Ohio,Oklahoma,Oregon,Pennsylvania,Rhode Island,South Carolina,South Dakota,Tennessee,Texas,Utah,Vermont,Virginia,Washington,West Virginia,Wisconsin,Wyoming}
Since the District of Columbia is included, there are 51 "states":
In[]:=
Length[$states]
Out[]=
51
In[]:=
sortedevotes=SortBy[evotes,Last]
Out[]=
{Alaska3,Delaware3,District of Columbia3,Montana3,North Dakota3,South Dakota3,Vermont3,Wyoming3,Hawaii4,Idaho4,Maine4,New Hampshire4,Rhode Island4,Nebraska5,New Mexico5,West Virginia5,Arkansas6,Iowa6,Kansas6,Mississippi6,Nevada6,Utah6,Connecticut7,Oklahoma7,Oregon7,Kentucky8,Louisiana8,Alabama9,Colorado9,South Carolina9,Maryland10,Minnesota10,Missouri10,Wisconsin10,Arizona11,Indiana11,Massachusetts11,Tennessee11,Washington12,Virginia13,New Jersey14,North Carolina15,Georgia16,Michigan16,Ohio18,Illinois20,Pennsylvania20,Florida29,New York29,Texas38,California55}
In[]:=
BarChart[Values[sortedevotes],BarOriginLeft,ChartLabelsKeys[sortedevotes],PlotLabel"Electoral Votes by State",ImageSize1024]
Out[]=
Question: how to win with the fewest states?
Question: how to win with the fewest states?
In[]:=
biggestStatesTo270=TakeWhile[Reverse[sortedevotes],Total[Drop[Values[sortedevotes],First@FirstPosition[sortedevotes,#]-1]]≤270&]
Out[]=
{California55,Texas38,New York29,Florida29,Pennsylvania20,Illinois20,Ohio18,Michigan16,Georgia16,North Carolina15,New Jersey14}
In[]:=
TableForm[biggestStatesTo270]
Out[]//TableForm=
California55 |
Texas38 |
New York29 |
Florida29 |
Pennsylvania20 |
Illinois20 |
Ohio18 |
Michigan16 |
Georgia16 |
North Carolina15 |
New Jersey14 |