% C2CVL2
% Tabulates the number of ways that the Dems can win in 2016 given 19
% competitive states. The number of possible Electoral College ties is also
% reported.
DemWins = 0; % Counts the number of Democratic Wins
nTies = 0; % Counts the number of ties.
% Nineteen loops. The loop counters encode the number of electoral votes
% from that state that are goingto the Democrats.
% The "SumThru" variables endodethe number of votes that have thus far been
% to the Democrats.
%
% COULD BE IMPROVED BY KEEPING TRACK OF REPUBLICAN VOTES AND TAKING SHORT
% CUTS WHEN THAT TOTAL >= 270.

for FL = 0:29:29 % # FL votes for Dems
for PA = 0:20:20 % # PA votes for Dems
for OH = 0:18:18 % # OH votes for Dems
for GA = 0:16:16 % # GA votes for Dems
% Note: even if FL, PA,OH, and GA all go to the Dems, still not 270 so no
% need to check.
for MI = 0:16:16 % # MI votes for Dems
SumThru_MI = 179+FL+PA+OH+GA+MI;
if SumThru_MI>=270
DemWins = DemWins + 2^14; % 14 states unassigned. Dems win regardless.
else
for NC = 0:15:15 % # NC votes for Dems
SumThru_NC = SumThru_MI + NC;
if SumThru_NC>=270
DemWins = DemWins + 2^13; % 13 states unassigned. Dems win regardless.
else
for VA = 0:13:13 % # VA votes for Dems
SumThru_VA = SumThru_NC + VA;
if SumThru_VA>=270
DemWins = DemWins + 2^12; % 12 states unassigned. Dems win regardless.
else
for AZ = 0:11:11 % # AZ votes for Dems
SumThru_AZ = SumThru_VA + AZ;
if SumThru_AZ>=270
DemWins = DemWins + 2^11; % 11 states unassigned. Dems win regardless.
else
for IN = 0:11:11 % # IN votes for Dems
SumThru_IN = SumThru_AZ + IN;
if SumThru_IN>=270
DemWins = DemWins + 2^10; % 10 states unassigned. Dems win regardless.
else
for MN = 0:10:10 % # MN votes for Dems
SumThru_MN = SumThru_IN + MN;
if SumThru_MN>=270
DemWins = DemWins + 2^9; % 9 states unassigned. Dems win regardless.
else
for MO = 0:10:10 % # MO votes for Dems
SumThru_MO = SumThru_MN + MO;
if SumThru_MO>=270
DemWins = DemWins + 2^8; % 8 states unassigned. Dems win regardless.
else
for WI = 0:10:10 % # WI votes for Dems
SumThru_WI = SumThru_MO + WI;
if SumThru_WI>=270
DemWins = DemWins + 2^7; % 7 states unassigned. Dems win regardless.
else
for CO = 0:9:9
SumThru_CO = SumThru_WI + CO;
if SumThru_CO>=270
DemWins = DemWins + 2^6; % 6 states unassigned. Dems win regardless.
else
for SC = 0:9:9
SumThru_SC = SumThru_CO + SC;
if SumThru_SC>=270
DemWins = DemWins + 2^5; % 5 states unassigned. Dems win regardless.
else
for OR = 0:7:7
SumThru_OR = SumThru_SC + OR;
if SumThru_OR>=270
DemWins = DemWins + 2^4; % 4 states unassigned. Dems win regardless.
else
for IA = 0:6:6
SumThru_IA = SumThru_OR + IA;
if SumThru_OR>=270
DemWins = DemWins + 2^3; % 3 states unassigned. Dems win regardless.
else
for NV = 0:6:6
SumThru_NV = SumThru_IA + NV;
if SumThru_NV>=270
DemWins = DemWins + 2^2; % 2 states unassigned. Dems win regardless.
else
for NM = 0:5:5
SumThru_NM = SumThru_NV + NM;
if SumThru_NM>=270
DemWins = DemWins + 2; % 1 state unassigned. Dems win regardless.
else
for NH = 0:4:4
SumThru_NH = SumThru_NM + NH;
if SumThru_NH>=270
% All states
% accounted for
% and Dems win..
DemWins = DemWins + 1;
elseif SumThru_NH == 269
% There is a tie..
nTies = nTies+1;
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
fprintf('\nCVL2: ties = %6d wins = %6d \n',nTies,DemWins)