[Question]
  [
When I was younger, I had a big map of the US tacked up on my wall across from my bed. When I was bored, I would stare at that map and think about stuff. Stuff like the four-color-theorem, or which state bordered the most other states. To save younger me some brainpower in counting, you are going to ~~invent a time machine and~~ tell me how many states border the input. Because time is finicky, this needs to be as short as possible.
# The Task
Given one of the 50 US states, either by its full name or by its postal abbreviation, as found on [this page](https://www.bls.gov/cew/cewedr10.htm) ([archive.org mirror](https://web.archive.org/web/20170526084535/https://www.bls.gov/cew/cewedr10.htm)), return the number of states it borders. The following is a mapping of all inputs for full state names to the number of states adjacent, found on [this website](http://state.1keydata.com/bordering-states-list.php).
```
Missouri, Tennessee -> 8
Colorado, Kentucky -> 7
Arkansas, Idaho, Illinois, Iowa, Nebraska, New York, Oklahoma, Pennsylvania, South Dakota, Utah, Wyoming -> 6
Arizona, Georgia, Massachusetts, Michigan, Minnesota, Nevada, New Mexico, Ohio, Virginia, West Virginia -> 5
Alabama, Indiana, Kansas, Maryland, Mississippi, Montana, North Carolina, Oregon, Texas, Wisconsin -> 4
California, Connecticut, Delaware, Louisiana, New Hampshire, New Jersey, North Dakota, Rhode Island, Vermont -> 3
Florida, South Carolina, Washington -> 2
Maine -> 1
Alaska, Hawaii -> 0
```
# The Rules
* Your program can either handle the full state name or the postal code - it cannot use a combination.
* You can specify the case of the input, but you cannot remove whitespace in the input.
* You do not have to handle Washington, D.C., or anything that is not one of the 50 states.
* The number of states bordered does **not** include the input state.
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so shortest answer in bytes wins.
While I know this may just be whoever has the best compression or finds the best regex pattern per number, if I get too many of those answers, I'll award a bounty to an answer that generates a map of the US and uses that to calculate the number of bordering states.
  
[Answer]
# Mathematica, 112 111 bytes
-5 byte thanks to [Mark S.](https://codegolf.stackexchange.com/users/41105/mark-s) and [LegionMammal978](https://codegolf.stackexchange.com/users/33208/legionmammal978)!
-22 bytes (and noticing a problem with the output) thanks to [ngenisis](https://codegolf.stackexchange.com/users/61980/ngenisis)!
```
Tr[1^Entity["AdministrativeDivision",#~StringDelete~" "]@"BorderingStates"]+Boole@StringMatchQ[#,"Il*"|"Mic*"]&
```
Of course, there's a Mathematica builtin for it. Includes D.C. in the count.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~73~~ 65 bytes
```
“U[“Ȥ“!÷2“®Ɓ⁵]StƁ}K“ʂÞiƬ¦.ÞrÆu“4œ(°fWg?Ʋd“Ɠ©“Œb‘i³OS%168¤$€Tµ’6L?
```
[Try it online!](https://tio.run/##y0rNyan8//9Rw5zQaCBxYgmQUDy83QhIHVp3rPFR49bY4JJjjbXeQIFTTYfnZR5bc2iZ3uF5RYfbSoFCJkcnaxzakBaebn9sUwqQf2zyoZVA6uikpEcNMzIPbfYPVjU0szi0ROVR05qQQ1sfNcw087H///@/kmdKYka@EgA "Jelly – Try It Online")
Builtins? Who needs those? (`ʂÞiƬ` on the ground in disgust).
Takes input as full name, such as `"Idaho"`.
**How it Works**
```
“U[“Ȥ“!÷2“®Ɓ⁵]StƁ}K“ʂÞiƬ¦.ÞrÆu“4œ(°fWg?Ʋd“Ɠ©“Œb‘i³OS%168¤$€Tµ’6L?
“U[“Ȥ“!÷2“®Ɓ⁵]StƁ}K“ʂÞiƬ¦.ÞrÆu“4œ(°fWg?Ʋd“Ɠ©“Œb‘                   The literal list of code-page index lists  [[85, 91], [154], [33, 28, 50], [8, 143, 133, 93, 83, 116, 143, 125, 75], [167, 20, 105, 152, 5, 46, 20, 114, 13, 117], [52, 30, 40, 128, 102, 87, 103, 63, 153, 100], [147, 6], [19, 98]]
                           €        On each sublist:
                         ¤            Evaluate the hash value:
                 ³                     Input
                   O                   Character values
                    S                  Sum.
                     %                 Modulus.
                      168              168
                i                     Does the sublist contain that nilad?
                            T       Get the sublist which does contain that nilad.
                                 ?  If
                                L     Length.
                                    Then
                             ’        Return the index - 1
                                    Else
                              6      Return 6
```
[Answer]
# JavaScript (ES6), ~~115~~ 113 bytes
*Edit: saved 2 bytes by borrowing 2 more string optimizations from [Step Hen Python answer](https://codegolf.stackexchange.com/a/139729/58563). I missed them on my initial attempt.*
Takes postal codes as input.
```
s=>('7KYCO8MOTN0AKHI1ME2FLSCWA3CACTNDELANHNJRIVT4ALWINCKSMDMSMTXOR5GAZOHMANMIMNVWVA'.match('.\\D*'+s)||'6')[0][0]
```
### How?
A non-RegExp argument passed to the `.match()` method is implicitly converted to a RegExp object. So, we're testing the regular expression `/.\D*{{input}}/` on our encoded string. This is matching a digit(1), followed by 0 to N non-digit characters, followed by the input.
For instance: if the input is `"NH"` (New Hampshire), the matched string will be `"3CACTNDELANH"`. We simply keep the first character of this string, or return `"6"` by default if there was no match.
*(1): The `.` is actually matching any character, but the string is built in such a way that what is found before a group of letters is always a digit.*
### Demo
```
let f =
s=>('7KYCO8MOTN0AKHI1ME2FLSCWA3CACTNDELANHNJRIVT4ALWINCKSMDMSMTXOR5GAZOHMANMIMNVWVA'.match('.\\D*'+s)||'6')[0][0]
const o = {
  8:['MO', 'TN'],
  7:['CO', 'KY'],
  6:['AR', 'ID', 'IL', 'IA', 'NE', 'NY', 'OK', 'PA', 'SD', 'UT', 'WY'],
  5:['AZ', 'GA', 'MA', 'MI', 'MN', 'NV', 'NM', 'OH', 'VA', 'WV'],
  4:['AL', 'IN', 'KS', 'MD', 'MS', 'MT', 'NC', 'OR', 'TX', 'WI'],
  3:['CA', 'CT', 'DE', 'LA', 'NH', 'NJ', 'ND', 'RI', 'VT'],
  2:['FL', 'SC', 'WA'],
  1:['ME'],
  0:['AK', 'HI']
};
for(let n = 8; n >= 0; n--) {
  o[n].forEach(s => {
    let res = f(s);
    console.log(s + ' -> ' + res + ' ' + (res == n ? 'OK' : 'FAIL'));
  });
}
```
---
# Hash version, 115 bytes
Same input format.
```
s=>`04436303035050063062750600644408${6e7}503600300540410005207058036442600400000650035`[parseInt(s,33)%589%180%98]
```
### Demo
```
let f =
s=>`04436303035050063062750600644408${6e7}503600300540410005207058036442600400000650035`[parseInt(s,33)%589%180%98]
const o = {
  8:['MO', 'TN'],
  7:['CO', 'KY'],
  6:['AR', 'ID', 'IL', 'IA', 'NE', 'NY', 'OK', 'PA', 'SD', 'UT', 'WY'],
  5:['AZ', 'GA', 'MA', 'MI', 'MN', 'NV', 'NM', 'OH', 'VA', 'WV'],
  4:['AL', 'IN', 'KS', 'MD', 'MS', 'MT', 'NC', 'OR', 'TX', 'WI'],
  3:['CA', 'CT', 'DE', 'LA', 'NH', 'NJ', 'ND', 'RI', 'VT'],
  2:['FL', 'SC', 'WA'],
  1:['ME'],
  0:['AK', 'HI']
};
for(let n = 8; n >= 0; n--) {
  o[n].forEach(s => {
    let res = f(s);
    console.log(s + ' -> ' + res + ' ' + (res == n ? 'OK' : 'FAIL'));
  });
}
```
[Answer]
# [Python 3](https://docs.python.org/3/), ~~168~~ ~~154~~ ~~153~~ 137 bytes
```
lambda s:[i for i,S in enumerate('AKHI ME FLSCWA CACTLANHNJNDERIVT ALWINCKSMDMSMTXOR MAZOHGANMIMNVWVA A KYCO MOTN'.split())if s in S]or 6
```
[Try it online!](https://tio.run/##LdHPb4IwFAfwu3/Fi5dCQoybm1tIPDQFBaFlAQb@mAcXJSNTNMIOxvi3s8erpw9tv699tOdr83OqRm0x@WoP2@P3bgu1vS6hOF2gtBIoK9hXf8f9ZdvsDcYDzwfpwjRMRM5BcJGGXHlqrhw39rMUeJj7SgSJdGQi00UUg@SryJtxJX2psjzjwCFYighklCo2qM@HsjFMsyyg7s5KNnjuuN3BBG5MRsx@txjmOgSO3iwWLAkeM3tsMd/RhBpOKFezJKKA@NBriS74TIlcR/iK2a8Wm3FCPvA1ilCZRhKRR2Q6mes1jk28YBOKCBJCOprHKCWUIKKYSBdE7hMC9xwhKeG4RKgnlaeZaxwi9olMF0yxiWf8TUHknJC4yxM2iDcxtJiHBcN7r9c98e/@2l37boAftWHaPThfyqox@re7Dbc7TPAd7v0BRo/bxsCQBUWHacFujW5Ms/0H "Python 3 – Try It Online")
*-4 bytes thanks to isaacg*
*-10 bytes thanks to ETHProductions*
*-1 byte thanks to notjagen*
Saved some more bytes by defaulting to six, as other answers have done.
TIO includes tests. Takes input as postal code. Generates a list of the state names as strings for each set, squished together where possible (for example, `WVVA` is stored as `WVA`). The lambda function gets the index in the list whose string contains the input. There may be a way I don't know about the golf the body of the function. Outputs as a list containing an integer - add `[0]` to the end of the lambda to output as integer.
[Answer]
# [V](https://github.com/DJMcMayhem/V), 143 bytes
```
çourüee/C8
çdoüke/C7
çrküI„sn]üebüOkünnsüSDüUüwy/C6
çzüg„ot]üttüinnüvaüxiüOh/C5
çbüdiüKüMáû5}üNCüOüTüWi/C4
ç^[CDLNRV]/C3
ç[FSW]/C2
çM/C1
ñlS0
```
[Try it online!](https://tio.run/##DYzNCoJQEEb3vcztz2o/EkRpkJULKSiUEuVeMLMfaCH0Iq1ct25Wfg92m905zPmmshaNuRbgJFE06aCJDTgTHgsXGXjWvi96J/cjeCmu9QUctLUL3oBvD0UjKZ/gU/s2pYRlCU61BlcH8D2V1VmRI408iEXnYA8f/JwX2G9rkgC8BoepoqFk@4jchb/a7hQNRKNpEAr2BT1FvQ6@edC1lkxuikNs/g "V – Try It Online")
Hexdump:
```
00000000: e76f 7572 fc65 652f 4338 0ae7 646f fc6b  .our.ee/C8..do.k
00000010: 652f 4337 0ae7 726b fc49 8473 6e5d fc65  e/C7..rk.I.sn].e
00000020: 62fc 4f6b fc6e 6e73 fc53 8144 fc55 fc77  b.Ok.nns.S.D.U.w
00000030: 792f 4336 0ae7 7afc 6784 6f74 5dfc 7474  y/C6..z.g.ot].tt
00000040: fc69 6e6e fc76 61fc 7869 fc4f 682f 4335  .inn.va.xi.Oh/C5
00000050: 0ae7 62fc 6469 fc4b fc4d e1fb 357d fc4e  ..b.di.K.M..5}.N
00000060: 8143 fc4f fc54 fc57 692f 4334 0ae7 5e5b  .C.O.T.Wi/C4..^[
00000070: 4344 4c4e 5256 5d2f 4333 0ae7 5b46 5357  CDLNRV]/C3..[FSW
00000080: 5d2f 4332 0ae7 4d2f 4331 0af1 6c53 30    ]/C2..M/C1..lS0
```
I wrote this before I realized you could take the input as postal codes. I'm not sure if that's actually shorter or not `:shrug:`. This answer uses regex to search for certain states, and then change the input to a certain number if it matches. However, as the number of states we've tested against goes up, the smallest search we can use goes down. So for example, we can't search for `C` because that will match `Colorado` and `California`. (As well as Conneticut and The Carolinas) However, once we've tested for every state that has more than 3 bordering, we can just search for *starts with C* because it can't match a previous one anymore.
A few test cases might be wrong since I don't have the time to test all of them. Let me know if you find any incorrect outputs. :)
[Answer]
# JavaScript, 153 bytes
```
MO=TN=8;CO=KY=7;AZ=GA=MA=MI=MN=NV=NM=OH=VA=WV=5;AL=IN=KS=MD=MS=MT=NC=OR=TX=WI=4;CT=DE=LA=NH=NJ=ND=RI=VT=3;FL=WA=2;ME=1;AK=HI="0";alert(self[prompt()]||6)
```
Variable chaining. I'm sure there's a better way to do this though.
Thanks to a suggestion from someone from Discord the output defaults to 6, the most common number of bordered states. 183 bytes to 151 bytes.
A commenter pointed out that this fails for AK and HI, so I've added two bytes to fix the issue. 151 to 153 bytes.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~78~~ 72 bytes
```
.•n£þuγ{çâ/₁=èó[nK™ΩFîÀî˜Çʒ÷¿ηZ¬³ã®ÿΣÔ¢*5ŠÜ‚!¶Ö¾#}ê(Ûø‰¢þL[Æ₁cgIkö•s¡¬ð¢
```
[Try it online!](https://tio.run/##AYsAdP8wNWFiMWX//y7igKJuwqPDvnXOs3vDp8OiL@KCgT3DqMOzW25L4oSizqlGw67DgMOuy5zDh8qSw7fCv863WsKswrPDo8Kuw7/Oo8OUwqIqNcWgw5zigJohwrbDlsK@I33DqijDm8O44oCwwqLDvkxbw4bigoFjZ0lrw7bigKJzwqHCrMOwwqL//2t5 "05AB1E – Try It Online")
---
```
.•n£þuγ{çâ/₁=èó[nK™ΩFîÀî˜Çʒ÷¿ηZ¬³ã®ÿΣÔ¢*5ŠÜ‚!¶Ö¾#}ê(Ûø‰¢þL[Æ₁cgIkö•
# Push the string: akhi me flscwa cactdelanhnjndrivt alinksmdmsncmtortxwi azgamamimnnvnmvaohwv idilianarenyokpnsdutwy kyco motn
s¡    # Split on input.
  ¬   # Get head.
   ð¢ # Count number of spaces.
```
---
This ONLY works because the order of the state abbreviations allows for NO state to occur in the overlap between states:
```
a[kh]i 
me 
f[ls][cw]a 
c[ac][td][el][an][hn][jn][dr][iv]t 
a[li][nk][sm][dm][sn][cm][to][rt][xw]i 
a[zg][am][am][im][nn][vn][mv][ao][hw]v 
i[di][li][an][ar][en][yo][kp][ns][du][tw]y 
k[yc]o 
m[ot]n
```
Took awhile to get the arrangement right... Then, by splitting on the input and counting the spaces in the first part, we get the correct result.
---
If I steal the "default to 6" from the other answers, I get 65 bytes:
# [05AB1E](https://github.com/Adriandmen/05AB1E), 65 bytes
```
.•3θ0ÔÕ—ú^?D§:‚A†ǝλα“i›p‚ιCöΔƒñPŠ J€ŽãB»ΣUÆ¤ÆuhÃgŠ¦,Y²•s¡¬ð¢D9Qi6
```
[Try it online!](https://tio.run/##AXwAg/8wNWFiMWX//y7igKIzzrgww5TDleKAlMO6Xj9Ewqc64oCaQeKAoMedzrvOseKAnGnigLpw4oCazrlDw7bOlMaSw7FQxaAgSuKCrMW9w6NCwrvOo1XDhsKkw4Z1aMODZ8WgwqYsWcKy4oCic8KhwqzDsMKiRDlRaTb//2lk "05AB1E – Try It Online")
[Answer]
# [Retina](https://github.com/m-ender/retina), ~~106~~ 105 bytes
```
MO|TN
8
CO|KY
7
AK|HI
0
ME
1
FL|WA
2
[CDLR].|N[HJD]|VT
3
.[CSX]|AL|IN|MD|MT|OR|WI
4
[GMV].|.[HMVZ]
5
..
6
```
[Try it online!](https://tio.run/##FY8/T8QwDEf39z2QmCr@wxo1pcm1cVAb0rurKsHAwMKAGP3di0@yvPhnP7/fr7/vn8/96rr/2FPWIrzQZh1OPOMGDZEbUsctr6MujjvW1o/T1qis4eA3rYV7mrWdj5u6UaNo8pqK5kmXyANrn6qlmzWket54pGl42g2FoYyEkXAT0RNHokM65EQeeHPMnvfCckmc6R3JKpIEqUgiB6pjqTa2VWGYSZ5kvSAteaIcsS9oC75jtOMBOSCeKWKfmxQmdRE0WUL8Bw "Retina – Try It Online") Did someone say regex? Edit: Saved 1 byte thanks to @Arnauld.
[Answer]
# JavaScript (ES6), 195 bytes
```
s=>/las|ii/[t='test'](s)?0:/ai/[t](s)?1:/Fl|Wa|S.*C/[t](s)?2:/fo|ct|de|ui|mp|er|^N.+ak/i[t](s)?3:/do|ck/[t](s)?7:/ur|ee/[t](s)?8:/iz|gi|ch|ev|xi|hi|es/[t](s)?5:/rk|ah|oi|ow|br|om|lv|ak/[t](s)?6:4
```
A series of regular expressions, which work on the state's full name.
**Test cases:**
```
var 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'];
let f=
s=>/las|ii/[t='test'](s)?0:/ai/[t](s)?1:/Fl|Wa|S.*C/[t](s)?2:/fo|ct|de|ui|mp|er|^N.+ak/i[t](s)?3:/do|ck/[t](s)?7:/ur|ee/[t](s)?8:/iz|gi|ch|ev|xi|hi|es/[t](s)?5:/rk|ah|oi|ow|br|om|lv|ak/[t](s)?6:4
for(i = 0 ; i <= 8 ; i++) {
  s = []
  states.forEach(st => f(st) == i && s.push(st))
  console.log(i + ' bordering states: ' + s.join(', '))
}
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~61~~ 59 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
OP%⁽/r%101eÐ€“¿=“þ“(7“¡¦ðø,0@L“€ç÷<CMZa“Ø!)5HNV““1^“¥+‘Tȯ7’
```
A full program taking the full state name and printing the result (as a monadic link it either returns a list containing a single number or the number 6).
**[Try it online!](https://tio.run/##y0rNyan8/98/QPVR4179IlVDA8PUwxMeNa151DDn0H5bIHl4H5DQMAfxFx5adnjD4R06Bg4@QC5Q0eHlh7fbOPtGJYLUzVDUNPXwCwPJNMwxjANpWKr9qGFGyIn1QN0z////75dalpiSCAA "Jelly – Try It Online")** or see a [test suite](https://tio.run/##TVJNb9NAEP0r5lAFRCWaA@ICEpUrSEidVFASFQTS1F7swZudaGfd1JwCF64ci9QLB@CCBDc48CHVQuJ35I@E/XDbSPbum9mZnfdm9qWQsl6tRnsby9e/buiN7lZXNO@Wb74sF6dnf@7Ytfltl6u3nP3h7FPzrfmxuXV315o2qPncfL8dJ0/AxZ1cuXazNxy7k8Vp97lL@Hh9uTjZ//fVZr9f/f3ZvLU5A/sfrFZPOwkyU6Wxsxl19oVSglkIZ8QkSUNGDg@EMlVa1g5v6xIUAzvcz6DwAX0pUREGJ83B7UNxqIHLFs@jA9Klw6NS2qyp9@/ZilzLI1Do7UdUmSLagZKMtx8bKNw@qWmKKg/18RUpf3pfkM5DYgLMkBYVC2M8iwTTAnNQATtd7ZVDcQTZBalEHGPqJYwK9PsY7Z0tnYlgE607tiUcQqDeVxlC4DG4aEgCupagslCV2X2zmW9uQsq08UPSVmUMmmzXvGekRU4qzOA4XDVBTkkxem8MEl@QblnEZPWkBtPKOHNHSJiD9lPbpQr5nJcT2IPpjAsMp87xQGgW9SWNy2Y/LCgTUZ/PBYyFnlrSDt6zbwGztRGtk5@ALaByEwQkgEq0vWqn37P0EDvP/gM "Jelly – Try It Online").
### How?
```
“¿=“þ“(7“¡¦ðø,0@L“€ç÷<CMZa“Ø!)5HNV““1^“¥+‘
```
is a list of lists of code-page indices:
```
[[11,61],[31],[40,55],[0,5,24,29,44,48,64,76],[12,23,28,60,67,77,90,97],[18,33,41,53,72,78,86],[],[49,94],[4,43]]
```
and is shown as `“ ... ‘`, below:
```
OP%⁽/r%101eÐ€“ ... ‘Tȯ7’ - Main link: list of characters, stateName  e.g. Ohio
O                        - cast to ordinals                   [79,104,105,111]
 P                       - product                                    95757480
   ⁽/r                   - base 250 literal                              12865
  %                      - modulo by 12865                                3285
      %101               - modulo by 101                                    53
             “ ... ‘     - list of lists of code-page indices
          eÐ€            - map: exists in?                 [0,0,0,0,0,1,0,0,0]
                    T    - truthy indices (if none yields an empty list)   [6]
                     ȯ7  - logical or with 7 (replace empty list with 7)   [6]
                       ’ - decrement                                       [5]
                         - implicit print (Jelly's representation of a list of
                         -                 one item is just that item)       5
```
[Answer]
# Excel VBA, ~~177~~ ~~154~~ 147 Bytes
Anonymous VBE function that takes input, of the expected type `String` representing a state's postal code, from range `[A1]`, and returns an `Integer` that represents the number of states that border that state.
```
For i=0To 8:r=r+IIf(Instr(1,Split("AKHI ME FLSCWA CACTLANHNJNDERIVT ALWINCKSMDMSMTXOR MAZOHGANMIMNVWVA | KYCO MOTN")(i),[A1]),i,0):Next:?IIf(r,r,6)
```
---
## Previous Versions
154 Bytes:
```
For Each s in Split("AKHI ME FLSCWA CACTLANHNJNDERIVT ALWINCKSMDMSMTXOR MAZOHGANMIMNVWVA | KYCO MOTN"):r=r+IIf(Instr(1,s,[A1]),i,0):i=i+1:Next:?IIf(r,r,6)
```
177 Bytes:
```
[2:2]=Split("AKHI ME FLSCWA CACTLANHNJNDERIVT ALWINCKSMDMSMTXOR MAZOHGANMIMNVWVA A KYCO MOTN"):[3:3]="=IfError(If(Find($A1,A2),Column(A3)),"""")":[B1]="=Sum(3:3)":?[If(B1,B1,6)]
```
Formatted for readability
```
[2:2]=Split("AKHI ME FLSCWA CACTLANHNJNDERIVT ALWINCKSMDMSMTXOR MAZOHGANMIMNVWVA | KYCO MOTN")
[3:3]="=IfError(If(Find($A1,A2),Column(A3)-1),"""")"
[B1]="=Sum(3:3)"
?[If(B1,B1,6)]
```
[Answer]
# Python 2, ~~363~~ 218 bytes
```
lambda a:dict(WA=2,WI=4,WV=5,FL=2,NH=3,NJ=3,NM=5,NC=4,ND=3,RI=3,NV=5,CO=7,CA=3,GA=5,CT=3,OH=5,KS=4,SC=2,KY=7,OR=4,DE=3,HI=0,TX=4,LA=3,TN=8,VA=5,AK=0,AL=4,VT=3,IN=4,AZ=5,ME=1,MD=4,MA=5,MO=8,MN=5,MI=5,MT=4,MS=4).get(a,6)
```
Let's start out with the ~~simple~~ slightly optimized hardcoded answer. Takes postal code as input.
-145 bytes thanks to bfontaine.
[Answer]
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 187 bytes
```
param($a)$x=($b=" MO8TN8CO7KY7AZ5GA5MA5MI5MN5NV5NM5OH5VA5WV5AL4IN4KS4MD4MS4MT4NC4OR4TX4WI4CA3CT3DE3LA3NH3NJ3ND3RI3VT3FL2SC2WA2ME1").IndexOf($a);if($x+1){$b[$x+2];exit}6-6*($a-in'AK','HI')
```
[Try it online!](https://tio.run/##FY5da8JAEEX/ikhgja0FMzMqiA/LRs022VnQJekHfYg0xYBasYKB4m/fbuFyz4Xzcs/ft@bys28OB@/P9aU@DqI6jrrFINot@j1jZ45nyk7z16l8o7UkE6LJMHFJbMhmVEqqSpIFasZ8iyZFE9ohK7QbdC9YaVQSlIN0CYUEzoCfgVPYaCgdrIpkq5JKJmY57sdP@vTZdPbr/8W8DegexvFvtHsPI/mYN117vU9Gk2Hwo/YkZC4eRaZF7L0XRos/ "PowerShell – Try It Online")
I'm sure there's a better way to do this, but here's the approach I came up with.
Takes input `$a` and uses that to get the `.IndexOf` its occurrence in the long string of state/border combinations. Stores that into `$x` and the string into `$b` in the process. Then goes into an `if` statement that checks whether it found a match, and if so index to the digit and then `exit`. Otherwise, we're one of the `6` states or `AK` or `HI`, so we perform some logic to see whether `$a` is either of the `0` states, and subtract if necessary. In any case, that's left on the pipeline and output is implicit.
[Answer]
# Python 3, 729 ~~733~~ bytes
Takes input as a postal abbreviation. This is my first attempt at a golfing challenge, and this is about the shortest I think I can get with this hellish approach. I know it's massive - come to think of it I'd probably have been better off with `if-else` statements, but after all of that time and effort I had to post it : D.
```
lambda s:sum((i-32)*96**j for j,i in enumerate(b'`*g$<#?wP\\.=)kuDbk$yvv\\D:Nh:cd/Pj, e*[_yXGz6lR<$jMo0qUU*7(Dua3-ThO}iX6VWRYDv=<K$8mVbYK9ld);TFB/m\'NE3ow4./pUsI5yJrwYrM4@e6\\kHJ%q8NA3>fb!~-rtwsRW=RBni}Y7T^gD\\IoxzJf.%|1.&4*"$%Q+).|8p(vcJ]cLRGUyC2eF:<Q4!_)y\\<`tr2A[z7re6OaR["2PRv\x7f,bRE [XrvtA<R<UlS23on?Byym&uy{XuB\x7fIMfh<y&waHElg-vk:4*on\x7f@?Ai5=2swfZSBF.PjkL{,|=,M<Bw"w,e@f`aKnmh\'xgg1#b4En\x7f+*\'g_ZRoeN*Q]mX\'>RoGc~ZP~e&{Hwo6bd<](hV)=l9#[f<Gj,#Ea!nJnL=9k"M,`bP2PsP6(eJoGEU>GA?,BpS}"RzzdMRtL[cre;\\tld^xT\':pry\'Nu_*R}eYg_U!Ld{p7<f:95lD]OBMX(r"Jg\'|%Cq"`Qy9g0aNrtYP9dnPRRr3\'yT(CE~\\&@5#tMLZ+a:V5NNXVp+Uy61s9$=Vb99(!ga7f7x}#=*]q.\x7f0R+f[*m:i^qe#D 8M&W\x7faGmCNCU9"~1Pj!]2r5 H>rYPqwfg4cFG*3-(z'))>>(5*int(s,36)-1850)&15
```
I just realised I'd taken the luxury of a three letter variable name - 4 bytes down, 400 to go!
]