# Win 270 electoral college votes

You are the electoral strategist for a sudden late entrant in the 2020 US presidental election.

Your task: print out the names of states* your candidate will win, totalling at least 270 electoral college votes.

## Background

Each state (and Washington DC) in the US system has an arbitrary number of "electoral college votes". A candidate has to win a majority of the 538 votes available, so at least 270 votes.

The number of votes for each state is:

[['Alabama', 9], ['Alaska', 3], ['Arizona', 11], ['Arkansas', 6], ['California', 55], ['Colorado', 9], ['Connecticut', 7], ['Delaware', 3], ['Florida', 29], ['Georgia', 16], ['Hawaii', 4], ['Idaho', 4], ['Illinois', 20], ['Indiana', 11], ['Iowa', 6], ['Kansas', 6], ['Kentucky', 8], ['Louisiana', 8], ['Maine', 4], ['Maryland', 10], ['Massachusetts', 11], ['Michigan', 16], ['Minnesota', 10], ['Mississippi', 6], ['Missouri', 10], ['Montana', 3], ['Nebraska', 5], ['Nevada', 6], ['New Hampshire', 4], ['New Jersey', 14], ['New Mexico', 5], ['New York', 29], ['North Carolina', 15], ['North Dakota', 3], ['Ohio', 18], ['Oklahoma', 7], ['Oregon', 7], ['Pennsylvania', 20], ['Rhode Island', 4], ['South Carolina', 9], ['South Dakota', 3], ['Tennessee', 11], ['Texas', 38], ['Utah', 6], ['Vermont', 3], ['Virginia', 13], ['Washington', 12], ['Washington DC', 3], ['West Virginia', 5], ['Wisconsin', 10], ['Wyoming', 3]]

None

## Output

A list (or similar) containing just the names of the states in your winning strategy. If a string, there must be separators between state names. States must be capitalised as in the list provided above.

You must not output anything other than valid state names and separators. The number of states in your strategy is up to you.

## Rules

You may not use any external (or built-in) list of US state names. Standard loopholes are forbidden.

This is code golf. Shortest code in bytes wins, with the electoral college score as a tie-breaker.

Since there is no input, your code can be a program/script/statement rather than a function.

If you are using space as a separator, then you can't include any states with spaces in the name. Or you would have to do something like enclosing each state name in double quotes. (A separator has to be something that could be used to automatically split the string up into the correct elements.)

* For the purpose of this challenge, Washington DC is considered a state.

• Related (Put together a Senate majority) – the default. May 8 '20 at 12:52
• Probably too late now, but I reckon it would've been interesting to have a scoring system that incentivised a high vote tally as well as a low byte count (something like bytes/votes, perhaps). – Dingus May 8 '20 at 13:10
• You may not use any external (or built-in) list of US state names ~> I think this is a borderline non-observable requirement. I suspect that Brotli has most (if not all) the states hard-coded in some internal dictionary. But I'm not supposed to know that, and I'm not even supposed to know that Charcoal uses Brotli under the hood. – Arnauld May 8 '20 at 16:41
• Related (Output the number of Electoral Votes one state has) – pppery May 9 '20 at 15:53
• Thanks, just did some reading. Less arbitrary than I realised: each state gets a proportional number of voters, plus 2. – Steve Bennett May 11 '20 at 2:04

# Charcoal,  52 ... 45  42 bytes (270 votes)

A list of states that optimizes the compression with Brotli.

”}∧J⟧´⪫3⎚>↘≡ＶＮb7>¹l↙⁵Þ7/…ξ⌕↑τc<y\MΦＧＣ＆⸿Dρ~


Try it online!

### Output

Texas
Pennsylvania
Georgia
Illinois
Washington
Indiana
California
Arizona
Michigan
Virginia
Florida
New York


### Node.js script

The initial list was found with the following Node.js script that shuffles the 30 most efficient states, extracts the shortest leading sub-list with a score greater than or equal to 270, joins it with \r and invokes the Brotli compressor on the resulting string.

It was optimized some more by shuffling the most promising sub-list to find an order offering the best compression.

let states = [ ['Alabama', 9], ['Alaska', 3], ['Arizona', 11], ... ];

states =
states.map(a => [a[0], a[1], a[1] / a[0].length])
.sort((a, b) => b[2] - a[2])
.slice(0, 30);

const zlib = require('zlib');

let bestLen = 1 / 0, bestScore = 1 / 0,
list, score, str, pack;

while(1) {
for(let i = states.length - 1; i > 0; i--) {
let j = Math.floor(Math.random() * (i + 1));
[ states[i], states[j] ] = [ states[j], states[i] ];
}

for(
let n = 1;
(score = (list = states.slice(0, n)).reduce((p, c) => p + c[1], 0)) < 270;
n++
) {}

str = list.map(s => s[0]).join('\r');
pack = zlib.brotliCompressSync(Buffer(str));

if(pack.length < bestLen || (pack.length == bestLen && score <= bestScore)) {
bestLen = pack.length;
bestScore = score;
console.log(bestLen, bestScore, str.split('\r').join('\\r'));
}
}

• I found the console.log(bestLen = pack.length, bestScore = score, str.split('\r').join('\\r')) syntax extremely worrying at first glance... – the default. May 8 '20 at 14:49
• @mypronounismonicareinstate Doing important assignments within a console.log?... What's wrong with that?!?... :-p – Arnauld May 8 '20 at 15:07
• I'm not sure whether that makes the results worse here, but Math.random() - 0.5 is not a transitive nor an anticommutative comparer and is unlikely to produce all permutations with similar probabilities, and according to a statistical analysis on a random blog, it's especially terrible on Chrome, and I assume that extends to V8 and to Node. (random information: I had C++ programs segfault with maximal optimization with a comparer that turned out not to be commutative in a rare edge case) – the default. May 8 '20 at 15:38
• @mypronounismonicareinstate That shouldn't matter much in that case. This method is especially bad for a single pass. But here, each iteration is shuffling the result of the previous one. (Also, we can't try all 30! ~= 2.65*10^32 permutations anyway.) – Arnauld May 8 '20 at 15:46
• @mypronounismonicareinstate Anyway, I've switched to Fisher-Yates as it can only be better, and is also much faster. Thanks! – Arnauld May 8 '20 at 16:26

# 05AB1E, 68 66 bytes, 271 votes

.•2Y±e1¸Zí¼³sçj†Êè”šʒÕʒ½‘ε-нUeC·ûÝì£…
õ%î!¯aàáè˜3ÒƵLweh³•#„€¢…Œ»™


Outputs the following 12 states newline-separated, totaling 271 votes:

California,Florida,Georgia,Illinois,Indiana,Michigan,Ohio,Pennsylvania,Texas,Utah,Virginia,New York


Try it online.

If builtins were allowed, we could have used the dictionary for 27 bytes, 270 votes

”‡Â†éŠ§›ÕïÁ–Û—Ñ—ïŽŽ‡¹¢ÇŸÏžÏ


Outputs the following 13 states space-delimited, totaling exactly 270 votes:

California Texas Florida Pennsylvania Illinois Ohio Michigan Georgia Virginia Washington Tennessee Massachusetts Indiana


Try it online.

Explanation:

.•2Y±e1¸Zí¼³sçj†Êè”šʒÕʒ½‘ε-нUeC·ûÝì£…
õ%î!¯aàáè˜3ÒƵLweh³• # Push compressed string "california florida georgia illinois indiana michigan ohio pennsylvania texas utah virginia"
#                 # Split it on spaces
# Push them all separated to the stack
„€¢…Œ           # Push dictionary string "new york" (which are both English words)
»          # Join all strings on the stack by newlines
™         # And title-case each word
# (after which it is output implicitly as result)

”‡Â†éŠ§›ÕïÁ–Û—Ñ—ïŽŽ‡¹¢ÇŸÏžÏ
# Push the dictionary string "California Texas Florida Pennsylvania Illinois Ohio Michigan Georgia Virginia Washington Tennessee Massachusetts Indiana"
# (after which it is output implicitly as result)

• .•2Y±e1¸Zí¼³sçj†Êè”šʒÕʒ½‘ε-нUeC·ûÝì£…\nõ%î!¯aàáè˜3ÒƵLweh³• is "california florida georgia illinois indiana michigan ohio pennsylvania texas utah virginia";
• „€¢…Œ is "new york";
• and ”‡Â†éŠ§›ÕïÁ–Û—Ñ—ïŽŽ‡¹¢ÇŸÏžÏ is "California Texas Florida Pennsylvania Illinois Ohio Michigan Georgia Virginia Washington Tennessee Massachusetts Indiana".

# Charcoal, 595150 41 bytes

”}∧I⊗⪫σ³»α“"⸿u↙¦Ｃ^±Ｗ)ＲLκ&⁰Ｙ2Ｅ¬«]f“ＷN+'|⁺≕


Try it online! Link is to verbose version of code. Simply the compressed string for Texas\nVirginia\nIllinois\nMichigan\nGeorgia\nPennsylvania\nFlorida\nWashington\nNew York\nCalifornia\nMassachusetts\nTennessee; total 270 votes.

This solution was found with the help of a Python 3 program that randomly selected voting states and took the length of the resulting string. It then tracked the number of times each state appeared in the strings that were less than a certain cutoff length, initially 60, but gradually reduced to 45 as I optimised the input.

Optimisation consisted both of creating a list of frequently used states and removing infrequently used states from the list thus allowing more shuffles to be performed.

Eventually I got to the point where each shuffle always had the states California, Florida, Georgia, Illinois, Michigan, New York, Pennsylvania and Texas, and four of the six states Arizona, Indiana, Massachusetts, Tennessee, Virginia and Washington. At this point I could generate all 15 combinations of 12 states and just had to shuffle the states around in the hope of getting a short answer. Shuffling script:

import brotli
import itertools
import random
import sys

bigstates = ['California', 'Florida', 'Georgia', 'Illinois', 'Michigan', 'New York', 'Pennsylvania', 'Texas']
smallstates = ['Arizona', 'Indiana', 'Massachusetts', 'Tennessee', 'Virginia', 'Washington']

while True:
for states in itertools.combinations(smallstates, 4):
states = bigstates + list(states)
for j in range(100):
random.shuffle(states)
if len(brotli.compress('\n'.join(states).encode("ascii"))) < 39:
print(states)
sys.exit()


Try it online! The script also found the following shuffles with the same byte count:

Print("Texas\nTennessee\nVirginia\nPennsylvania\nWashington\nCalifornia\nMichigan\nMassachusetts\nNew York\nGeorgia\nFlorida\nIllinois");
Print("Texas\nVirginia\nMichigan\nIllinois\nGeorgia\nPennsylvania\nFlorida\nWashington\nTennessee\nMassachusetts\nNew York\nCalifornia");
Print("Texas\nGeorgia\nTennessee\nVirginia\nIllinois\nPennsylvania\nMichigan\nWashington\nCalifornia\nNew York\nMassachusetts\nFlorida");
Print("Texas\nNew York\nVirginia\nPennsylvania\nWashington\nFlorida\nMassachusetts\nGeorgia\nCalifornia\nTennessee\nMichigan\nIllinois");


Previous 50-byte solution:

”}∧UV↔ΦＪU№ＥIＧ➙eêPn¡Ｆ{⦃←στ⸿Ｍ⊕!⪫¹Ｐ？Ｍξ⁹#<″⊘bh%0ＲＺ⌈⧴↑·


Try it online! Link is to verbose version of code. Simply the compressed string for Pennsylvania\nWisconsin\nTexas\nCalifornia\nIllinois\nNew York\nFlorida\nGeorgia\nMichigan\nVirginia\nArizona\nNew Jersey; total 271 votes.

I started off with the best value states, Texas, California, Florida, Ohio, New York, Illinois, Georgia, Michigan, Pennsylvania, Virginia and Arizona, plus Iowa to make up the numbers. I then tried various permutations of states to find out which ones Charcoal compressed best; moving Ohio, Illinois and New York to the end worked best. (There are 12! possibilities so I'm not trying them all.) I then tried switching Arizona and Iowa with Indiana and Utah, taken from @SurculoseSputum's answer; Arizona made no difference but Utah saved a further byte.

Edit: Saved 8 bytes by printing Utah and Ohio literally instead of trying to compress them. Saved a further byte by using New Jersey and Wisconsin instead of Utah and Ohio. (This did mean reordering the states again for optimal compression. Colorado, Indiana, Maryland, Massachusetts, Minnesota, Mississippi and Missouri and also work instead of Wisconsin.)

# Python 2, 106 bytes, 271 votes

print"California,Florida,Georgia,Illinois,Indiana,Michigan,New York,Ohio,Pennsylvania,Texas,Utah,Virginia"


Try it online!

Picks the states with the best votes/name length ratio.

Turns out this is the shortest possible combination of states to achieve at least 270, as shown in this DP program.

• There's actually a shorter combination with just 11 states: California (55; 55) Texas (38; 93) Florida (29; 122) New York (29; 151) Illinois (20; 171) Pennsylvania (20; 191) Ohio (18; 209) Georgia (16; 225) Michigan (16; 241) North Carolina (15; 256) New Jersey (14; 270) – ouflak May 8 '20 at 14:35
• @outflak while your list has less states, the total length is 4 bytes longer than my current answer. – Surculose Sputum May 8 '20 at 14:36

# Turing Machine Code, 1059 bytes (270 votes)

0 * C r 1
1 * a r 2
2 * l r 3
3 * i r 4
4 * f r 5
5 * o r 6
6 * r r 7
7 * n r 8
8 * i r 9
9 * a r π
π * , r a
a * T r b
b * e r c
c * x r d
d * a r e
e * s r f
f * , r g
g * F r h
h * l r i
i * o r j
j * r r k
k * i r l
l * d r m
m * a r n
n * , r o
o * N r p
p * e r q
q * w r r
r * _ r s
s * Y r t
t * o r u
u * r r v
v * k r w
w * , r x
x * I r y
y * l r z
z * l r A
A * i r B
B * n r C
C * o r D
D * i r E
E * s r F
F * , r G
G * P r H
H * e r I
I * n r J
J * n r K
K * s r L
L * y r M
M * l r N
N * v r O
O * a r P
P * n r Q
Q * i r R
R * a r S
S * , r T
T * O r U
U * h r V
V * i r W
W * o r X
X * , r Y
Y * G r Z
Z * e r 
* o r ¬
¬ * r r "
" * g r £
£ * i r  * a r %
% * , r ^
^ * M r &
& * i r (
( * c r )
) * h r +
+ * i r {
{ * g r }
} * a r [
[ * n r ]
] * , r -
- * N r =
= * o r :
: * r r '
' * t r @
@ * h r #
# * _ r ~
~ * C r
> * o r .
. * l r ?
? * i r /
/ * n r |
| * a r \
\ * , r ©
© * N r À
À * e r Á
Á * w r Â
Â * _ r Ã
Ã * J r Ä
Ä * e r Å
Å * r r Æ
Æ * s r Ç
Ç * e r È
È * y r halt



This will print:

California (55; 55)
Texas (38; 93)
Florida (29; 122)
New York (29; 151)
Illinois (20; 171)
Pennsylvania (20; 191)
Ohio (18; 209)
Georgia (16; 225)
Michigan (16; 241)
North Carolina (15; 256)
New Jersey (14; 270)


Or to be more precise: California,Texas,Florida,New York,Illinois,Pennsylvania,Ohio,Georgia,Michigan,North Carolina,New Jersey

Updated to reflect later rule change thanks @Laikoni. No byte size change.

Try it online!

• The challenge states "If you are using space as a separator, then you can't include any states with spaces in the name." – Laikoni May 10 '20 at 10:27
• @Laikoni, Thanks for the update. Wouldn't have known otherwise. Wonder if there couldn't be some feature for this site where an OP could 'ping' the answerers if there are significant changes that might affect their answers? – ouflak May 10 '20 at 12:09
• I was not aware that this rule was added to the challenge after you posted your answer. It would have been nice if OP informed the existing answers of this change - the 'ping' you mention is easily achieved by commenting on the answers, especially as there weren't that many. – Laikoni May 11 '20 at 13:13
• Sorry, my bad. (From my point of view, it wasn't "adding a rule", but explicitly stating something that I thought was implicit in the use of the word "separator", but point taken.) – Steve Bennett May 11 '20 at 13:28

# Stax, 75 bytes, 271 votes

ê╢G.₧¢ƒdXb╜L7äF9₧⌐Ä╚ç⌂oPrçer┬♦s4⌠╧!S∟☻ƒÆà²ÿ☼{4?àç÷Uó("Φå9dgYútY°lènÜÉ↔TI╙í↨


Run and debug it

# Ruby, 115 bytes

puts"California
Texas
Florida
Nor#{s="th Carolina
New "}York
Sou#{s}Jersey
Illinois
Ohio
Georgia
Michigan
Virginia"


Try it online!

Makes use of the string "th Carolina\nNew "

• @mathjunkie. Thanks, I noticed that after posting. I also noticed that a port of Surculose Sputum's simpler but better researched answer would be shorter than this/ But I'll leave it up as I wanted to share the Carolina/New concept. – Level River St May 9 '20 at 2:56
• I'm glad there are languages that manage to make use of the New/North/South duplications. I tried with JavaScript but didn't save any bytes. – Steve Bennett May 9 '20 at 7:54

# Jelly, 37 bytes

“£+ʠṅṖḳ!⁺PUB.BJçŒṖ{ScḤ?[¢¤c}€£Y,qbẆ|»


A niladic Link which yields a list of characters using a space as the separator. The states have a total value of 270 (and contain no spaces themselves):

California    55
Texas         38
Florida       29
Pennsylvania  20
Illinois      20
Ohio          18
Georgia       16
Virginia      13
Massachusetts 11
Indiana       11
Arizona       11
Maryland      10
Colorado       9
Alabama        9
= 270


Try it online!

### How?

A compressed string. After taking big hitters containing no spaces I chose states which are earlier alphabetically to keep the result shorter.

# Bash, 102 108 bytes (270 electoral votes)

echo \"{{Californ,Georg,Virgin}ia,Florida,Arizona,Indiana,Texas,Ohio,New\ {York,Jersey},Illinois,Michigan}\"


Try it online!

Added 6 bytes to accommodate the modification to the challenge on using a space as a separator. The original answer was:

echo {Californ,Georg,Virgin}ia Florida Arizona Indiana Texas Ohio New\ {York,Jersey} Illinois Michigan

• This uses space as a separator, but also includes states with spaces in their names, which isn't valid. (I've updated the rules to clarify this). Sorry if that feels like moving the goalposts - but it doesn't seem right to call something a "separator" if you can't split on it. – Steve Bennett May 9 '20 at 14:20
• I've accommodated the new rule on spaces at the cost of 6 bytes. – Mitchell Spector May 9 '20 at 14:49

## JavaScript, 114 characters, 270 votes

_=>California,Texas,Florida,Nor${s='th Carolina,New '}York,Sou${s}Jersey,Illinois,Ohio,Georgia,Michigan,Virginia


Just a straight port of Level River St's Ruby answer.

# Whitespace, 777 bytes; 274 EV's





Outputs the states as a j-separated list. You read that part right.
Try it online!

## States

"Arizona", "California", "Florida", "Georgia", "Illinois", "Indiana", "Iowa", "Michigan", "Ohio", "Pennsylvania", "Tennessee", "Texas", "Utah", "Virginia"
List chosen using @Surculose Sputum's Python script, but modified to ignore states with spaces in their names. This was because spaces have an ascii value of 32, and 32 - 105= -73, so pushing it would raise the byte count by a lot (I think). I have yet to test this theory though (because when removing NY I had to add something like 4 more states), so the code may yet get smaller.

## Code

A pretty standard Whitespace answer. Pushes the names of the states minus 105 to the stack, separated by a j, and then runs through the stack adding back the 105 and printing the result as a character. The printing part looks something like:

label 0:
push 105
add
printc
jmp 0


105 because the character with the most occurences is i, which has an ascii value of 105. Outputting as a j separated list because j has a value of 106. I used this script to generate the WSA (WhiteSpace Assembly) to quickly test the offset number, and used this IDE to compile it to regular Whitespace.