[Question]
  [
[Abbreviate that US state!](https://codegolf.stackexchange.com/questions/122896/abbreviate-that-us-state/122925?noredirect=1#comment304738_122925) was fun, but we learnt that efficiently abbreviating US state names is hard with the current system. Let's come up with an alternative state code scheme for efficient golfing.
Your task:
> 
> Write a function (or program) which, given a valid US state name (only the 50 normal states required), returns a unique two-letter code in uppercase identifying it. The code must meet these requirements:
> 
> 
> * The first letter must be the same as the first letter of the state.
> * The second letter must be one of the other letters of the state (not a space).
> * It must always give the same output for the same input, and must never give the same output for two different valid inputs.
> 
> 
> 
For instance, given "Alabama", your function could return "AL", "AA", "AB" or "AM" - as long as it doesn't return that value for any of Alaska, Arkansas, etc. ("AA" is only possible because "A" appears more than once in the state name.)
Standard loopholes forbidden. Standard input/output are ok. This is code golf, so shortest solution, in bytes, wins.
The complete list of possible inputs is here:
```
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
```
  
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~13~~ 12 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
907ị;⁸Qḣ2ṢŒu
```
A monadic link taking and returning lists of characters.
**[Try it online!](https://tio.run/##y0rNyan8/9/SwPzh7m7rR407Ah/uWGz0cOeio5NK////75tZXAxCBQWZAA)** or see a [test suite](https://tio.run/##XZG9TuNAEIBfxV2aKxDN6XQVCgIMJOHvQCdEMdhDPHizE@2sCaaDhoLuHgFaHgAE3YkHSV7E7I8NAmml/eb/7xyVqpvm19LP@cvd78X10@786WF5/nz/9q9q3l7/3y5uHteb5ri3ouAUJtD7kXiUMpKhK9YtlqAFxHMfFJ2x0RQsfVZsIOfIWmNmKausF1dRwQwMel5zXpSHiHVkM47BG85O5CnNoQg5UqVIM4VKqc4JYgMpz8K/9dHGFmpbZWXteZsrks51AKQxgqkV6DyyCGRFJWhtCB9QVtAYdGTXt7CN4STi33RKnciViczatkWGeGq6PQ3xAvKWZskGTKZSUBzbKzbRCNadNMBLyriT/rIpA7OxRdIHw256@NSsQtm2NSooRI1K5TYVTzUyOOYwwQ5qLbW6gPYqewXnmKTSjb/P1bf8UfOZ/wD9DgQxCpdxyX8sFP4/RDNxwwckd722zBG4SfXYxiaOUGzyxUySsRaK1ponzrd38g4)
### How?
```
907ị;⁸Qḣ2ṢŒu - Monadic link: list of characters, state    e.g. Alabama   or   Kansas
907          - literal 907
   ị         - index into state                                b              K
     ⁸       - link's left argument, state
    ;        - concatenate                                     bAlabama       KKansas
      Q      - de-duplicate (unique by 1st appearance)         bAlam          Kans
       ḣ2    - head to index 2                                 bA             Ka
         Ṣ   - sort                                            Ab             Ka
          Œu - convert to uppercase                            AB             KA
```
Indexing in Jelly is 1-indexed and modular, so the 907th index of something of length L is the (907-modulo-L)th item. For example for "Alabama" the length is 7 so the item at index 907 is the (907-modulo-7)th, and 907-modulo-7 is 4 (907 = 129 \* 7 + **4**), so the item at index 907 is 'b'.
907 is the first positive index at which the state abbreviations using index 1 and that index over all of the 50 states become unique.
State names, including their spaces, are of length 4 through 14 inclusive, and 907-modulo-6 is 1 (whereas for all other lengths the value is not 1). This means that if we were to use the 1st and 907th characters for the abbreviations that Alaska, Hawaii, Kansas, Nevada, and Oregon would be AA, HH, KK, NN, and OO respectively - this is not acceptable for Hawaii, Kansas, or Nevada; so an adjustment needs to be made; this is the reason for the concatenation, de-duplication, head to index 2 and sort, this makes Alaska, Hawaii, Kansas, Nevada, and Oregon become AL, HA, KA, NA and OR respectively and does not collide with existing state abbreviations.
[Answer]
# Ruby, 34 bytes
```
->s{s[0]+(s[1,8]*999)[445].upcase}
```
I started off with `s[0]+s*99999[x].upcase` and found many values of x up to x=100000 which returned unique codes for all 50 states. Unfortunately they all had cases where the second letter of the abbreviation was the first letter of the state duplicated, which is not allowed (unless the letter appears twice in the state name.) So I decided to use the expression `s[0]+s[1,8]*999[x]` and found the smallest value of x that worked was 445.
**Commented in test program, and output**
```
f=->s{s[0]+            #Return character 0 of the input. Then..
(s[1,8]*999)[          #Concatenate 999 copies of the 8 characters starting at character 1 (or till end of name if state has less than 9 characters) 
   445].upcase         #Return character 445 of the result, converted to uppercase. 
}                     
"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".split($/).map{|i|p [f[i],i]}
["AA", "Alabama"]
["AL", "Alaska"]
["AI", "Arizona"]
["AS", "Arkansas"]
["CR", "California"]
["CA", "Colorado"]
["CT", "Connecticut"]
["DA", "Delaware"]
["FO", "Florida"]
["GO", "Georgia"]
["HA", "Hawaii"]
["IA", "Idaho"]
["IO", "Illinois"]
["ID", "Indiana"]
["IW", "Iowa"]
["KA", "Kansas"]
["KC", "Kentucky"]
["LA", "Louisiana"]
["MI", "Maine"]
["MA", "Maryland"]
["MH", "Massachusetts"]
["MG", "Michigan"]
["MO", "Minnesota"]
["MS", "Mississippi"]
["MU", "Missouri"]
["MN", "Montana"]
["NS", "Nebraska"]
["NE", "Nevada"]
["NM", "New Hampshire"]
["NR", "New Jersey"]
["NX", "New Mexico"]
["NO", "New York"]
["NC", "North Carolina"]
["ND", "North Dakota"]
["OI", "Ohio"]
["OO", "Oklahoma"]
["OR", "Oregon"]
["PL", "Pennsylvania"]
["RI", "Rhode Island"]
["SC", "South Carolina"]
["SD", "South Dakota"]
["TS", "Tennessee"]
["TX", "Texas"]
["UA", "Utah"]
["VR", "Vermont"]
["VN", "Virginia"]
["WG", "Washington"]
["WI", "West Virginia"]
["WS", "Wisconsin"]
["WO", "Wyoming"]
```
[Answer]
# [Python 2](https://docs.python.org/2/), 39 bytes
```
lambda s:s[0]+s[906%len(s)or 1].upper()
```
[Try it online!](https://tio.run/##bZJtaxNBEIC/51fsF0mCtbQigoEKkqKNNY3YapGYD5O7SW64vZ1jZ6/pNeS3x325sygeB/vM687MTt26gs3r4@bi11FDtc5ByUSWZ6uXsnx39vaFRjOSMVt1vjpt6hrtaHwUBw5FXajl8IOGNVQwPFEBpUxk6YlNhyUYAQk8BU0btoaiZcqaLeSc2BjMHGWNC@IlatiBxcAfvRflMeITst2m4CtvJwo0y6GIOWZak2GKN81MTpAKmPEuntd/yrhG45qsbAN/4Yakd50DGUxgWw0mTywCWdEIOhfD55QVtAWT2Nct7FI4iYS/rqkXubGJ2bjukhtc235ON/gAeUc7dQVVLQWltoPiM1rBtpfm@EgZ99JPtmVktq5QU7Dsu4dnzSWUXVmLgmLUotR@UumpFha3HDv4isZIqx@ge5VvBeeoZtK3f8vNP/mT5jn/HYYZCGISHtOQvzsowvkDbeWbj0j@9bpr7sF3arYuFXGP4tRfZpKMjVCytlx53@FqMKgtGafCSu43o7iFY@U3SkVUZBLIYTwY/Ec9GSj/pRzD/eT8zeHVe7U/DE@9bwUuJTxRfebx8Tc "Python 2 – Try It Online")
## [Python 2](https://docs.python.org/2/), 39 bytes
```
lambda s:s[0]+s[306%len(s)or-3].upper()
```
[Try it online!](https://tio.run/##bZLdb9NADMDf@1fcC2ortmkwxEOlIaFOsDK6IgZMqPTBTdzGyuUcnS/rQtW/vbuPhAlEFOl@/jzb57p1BZvXx83lr6OGap2Dkoksz1cvZXlx/vaFRjOSMdvTi9VZU9doR@OjOHAo6lIth@81rKGC4YkKKGUiS7/ZdFiCEZDAU9C0YWsoWqas2ULOiY3BzFHWuCBeoYYdWAz8wXtRHiM@ItttCr72dqJAsxyKmGOmNRmmeNPM5ASpgBnv4nnzp4wbNK7JyjbwZ25Ietc5kMEEttVg8sQikBWNoHMxfE5ZQVswiX3dwi6Fk0j465p6kRubmI3rLrnFte3ndIsPkHe0U9dQ1VJQajsoPqEVbHtpjo@UcS/9ZFtGZusKNQXLvnt41lxB2ZW1KChGLUrtJ5WeamFxy7GDL2iMtPoBulf5WnCOaiZ9@3fc/JM/aZ7zf8MwA0FMwmMa8ncHRTh/oK188xHJv153zT34Ts3WpSLuUZz6y0ySsRFK1pYr7ztcDQa1JeNUWMn9ZhS3cKz8RqmIikwCOYwHg/@oJwPlv5RjuJ@8enM4faf2h@GZ963ApYQnqs88Pj4B "Python 2 – Try It Online")
[Answer]
## JavaScript (ES6), 46 bytes
```
s=>s[0]+s[(s>'M')+1153%s.length].toUpperCase()
```
### Demo
```
let f =
s=>s[0]+s[(s>'M')+1153%s.length].toUpperCase()
;[
  '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'
]
.map(
  s => console.log(f(s), s)
)
```
[Answer]
# [Retina](https://github.com/m-ender/retina), ~~49~~ 46 bytes
```
\B.*(?=[A-Zflmpxz])|\B.*(?=[hru])
T`l`L
!`^..
```
[Try it online!](https://tio.run/##TVDbThtBDH33V6QPlaBS8wcI0aDCAklQS0G9UMXsmoy1s3Y0niVZxL@nnoWqlUbj44uOfU6izIL79wdnq/2vT9MPB8dHP08@/niM3Wb3fH/48rcWUn9/CHCziqsreLf6PZ3u9ycRH7BD8Gith8TPKiW2KIYGM4z8qEkYYaZREzbqQITqzHWf4ZQibjERfPYmNwhnpGnt0@deZoaqwaBQxciibFBJw@j8lW4RLl9XXJLkvm4HuNKebWzPkYX8T0NEaRyYYR16o5wN5lwHXqM48DtMs8@zWXmbDY9Y@@RAJReyBT2kUdyCnrApYTs5x25jgf3ukl1QMhpGOKcd1zrC75paWGjKYTLDpK4A39JTbMvWZWCFZRtdoTu4TLRWgWsSsSE@YbHsS9CGJpWNKr5q/z/Va/pGdUNFihE52rkn3zIGuKXUuQa4ZXe00N2h3yzr7GvuyPLkX4OtVjH2@qCdj/wB "Retina – Try It Online") If the state contains a second uppercase letter, or one of the letters `flmpxz`, then that becomes the second letter of the code. Otherwise, if it contains one of the letters `hru`, then that becomes the second letter of the code, otherwise just use the first two letters of the state.
[Answer]
# JavaScript (ES6), 52 bytes
```
s=>s[0]+(s=s.slice(2,9))[146%s.length].toUpperCase()
```
```
f=
s=>s[0]+(s=s.slice(2,9))[146%s.length].toUpperCase()
states = `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`.split('\n')
states.forEach(state => console.log(f(state), state))
```
---
# JavaScript (ES6), 52 bytes
```
s=>s[0]+(s[8]||s[s[1]=='o'?5:4]||s[2]).toUpperCase()
```
```
f=
s=>s[0]+(s[8]||s[s[1]=='o'?5:4]||s[2]).toUpperCase()
states = `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`.split('\n')
states.forEach(state => console.log(f(state), state))
```
]