50
6
Given one of the 50 U.S. state names on the left as input, output its two-letter postal code as shown to the right:
Alabama AL
Alaska AK
Arizona AZ
Arkansas AR
California CA
Colorado CO
Connecticut CT
Delaware DE
Florida FL
Georgia GA
Hawaii HI
Idaho ID
Illinois IL
Indiana IN
Iowa IA
Kansas KS
Kentucky KY
Louisiana LA
Maine ME
Maryland MD
Massachusetts MA
Michigan MI
Minnesota MN
Mississippi MS
Missouri MO
Montana MT
Nebraska NE
Nevada NV
New Hampshire NH
New Jersey NJ
New Mexico NM
New York NY
North Carolina NC
North Dakota ND
Ohio OH
Oklahoma OK
Oregon OR
Pennsylvania PA
Rhode Island RI
South Carolina SC
South Dakota SD
Tennessee TN
Texas TX
Utah UT
Vermont VT
Virginia VA
Washington WA
West Virginia WV
Wisconsin WI
Wyoming WY
Rules
- Input and output are both case sensitive. You many not output e.g.
Al
forAlabama
. - You may assume the input is one of the 50 state names shown above.
- You may not access the internet or use built-in state data (looking at you, Mathematica).
Separate lists of inputs and outputs can be found in this snippet (please don't run it, it's just for compressing the post):
Alabama
Alaska
Arizona
Arkansas
California
Colorado
Connecticut
Delaware
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
AL
AK
AZ
AR
CA
CO
CT
DE
FL
GA
HI
ID
IL
IN
IA
KS
KY
LA
ME
MD
MA
MI
MN
MS
MO
MT
NE
NV
NH
NJ
NM
NY
NC
ND
OH
OK
OR
PA
RI
SC
SD
TN
TX
UT
VT
VA
WA
WV
WI
WY
(Non-scoring) Brownie points if you can also take District of Columbia
as input and produce DC
, Virgin Islands, etc etc.
Scoring
This is code-golf, so the shortest code in bytes in each language wins.
(Originally proposed by ETHProductions)
1Related (another challenge about US states) – Mego – 2017-05-26T06:37:08.583
11For those curious to know Mathematica's approach:
Entity[a="AdministrativeDivision",{#,"UnitedStates"}]@EntityProperty[a,"StateAbbreviation"]&
– DavidC – 2017-05-26T07:05:31.87012@BetaDecay Questions that are closed as off-topic are not useful dupe targets. – Mego – 2017-05-26T07:08:48.893
7@DavidC You can save
20
bytes:Entity["AdministrativeDivision",{#,"UnitedStates"}]@"StateAbbreviation"&
:) – ngenisis – 2017-05-26T18:28:42.2731How is this a Kolmogorov complexity question? I thought this tag is for constant output – Felix Dombek – 2017-05-26T18:59:09.810
@ngenisis, nice shortcut (that I was not aware of)! – DavidC – 2017-05-26T19:20:00.810
Would've been more interesting if you had included territories and federate states. ;) – jpmc26 – 2017-05-26T22:57:55.370
@FelixDombek It's more about efficiently generating a set of data, even if not all of it is output. – Esolanging Fruit – 2017-05-27T00:44:33.767
@FelixDombek https://codegolf.meta.stackexchange.com/a/9909/45941
– Mego – 2017-05-27T07:07:54.0632Offer extra credit for including the other 12 two-character codes in the complete official list of US postal abbreviations: AA (ARMED FORCES AMERICAS), AE (ARMED FORCES EUROPE), AP (ARMED FORCES PACIFIC), AS (AMERICAN SAMOA), DC (DISTRICT OF COLUMBIA), FM (FEDERATED STATES OF MICRONESIA), GU (GUAM), MH (MARSHALL ISLANDS), MP (NORTHERN MARIANA ISLANDS), PR (PUERTO RICO), PW (PALAU), VI (VIRGIN ISLANDS). – joe snyder – 2017-05-27T15:47:45.487
1Also, this is a code-golf, while the proposed duplicate was a pop-con – John Dvorak – 2017-05-27T17:28:55.550
2Yeah this is not a dupe. – Christopher – 2017-05-27T18:27:16.570
Also the question listed as a dupe is closed as off topic where this one clearly isn't off topic. – Ian Miller – 2017-05-28T01:00:00.867
2Heh, I only just noticed that someone actually closed this as a dupe. FFS. – Steve Bennett – 2017-05-28T01:22:00.180
@joesnyder I've made clearer in the challenge that non-scoring Brownie points are available for all of those extensions. It says in the guidelines somewhere that bonus points are generally discouraged. Also this isn't my challenge. Also, I prefer this tighter challenge. – Steve Bennett – 2017-05-28T01:23:44.453