的JavaScript(ES6), 203个202 201 200字节
@NahuelFouilleul节省了1个字节
s=>'xMiAZGAWaMIOhNvInxMNNmARKSKYLANDOrNMPrAKIAMIMSMPSCVtAsMdxScRiNhUtDcCtxFlxNYNCPATXVAWiInIlINOkNjCaTn'.match(/[A-Z]*./g)[s.replace(/./g,c=>c<'!'?0:1/c?9:6-~(c+1))*3%47%30].toUpperCase().match(/../g)
在线尝试!
怎么样?
输入转换
ñ
作为JS代码:
c < '!' ? // if c is a space:
0 // replace it with 0
: // else:
1 / c ? // if c is a digit:
9 // replace it with 9
: // else:
6 - ~(c + 1) // if c is a hyphen, this gives:
// 6 - ~('-1') --> 6 - 0 --> 6
// if c is a letter (e.g. 'A'), this gives:
// 6 - ~('A1') --> 6 - ~NaN --> 6 - (-1) --> 7
哈希函数
然后,我们应用以下哈希函数:
F( n )= ((3 × n )mod 47 )mod 30
[ 1..29 ]000AA
AAA000
24
format | n | * 3 | mod 47 | mod 30 | states
------------+----------+-----------+--------+--------+----------------------
'AAA 000' | 7770999 | 23312997 | 10 | 10 | AK,IA,MI,MS,MP,SC,VT
'0000' | 9999 | 29997 | 11 | 11 | AS
'AAA0000' | 7779999 | 23339997 | 32 | 2 | AZ,GA,WA
'000 AAA' | 9990777 | 29972331 | 8 | 8 | AR,KS,KY,LA,ND,OR
'0AAA000' | 9777999 | 29333997 | 28 | 28 | CA
'AA-00000' | 77699999 | 233099997 | 19 | 19 | CT
'AA-0000' | 7769999 | 23309997 | 18 | 18 | DC
'AAA A00' | 7770799 | 23312397 | 21 | 21 | FL
'AA 00000' | 77099999 | 231299997 | 25 | 25 | IL
'000A' | 9997 | 29991 | 5 | 5 | IN
'000AA' | 99977 | 299931 | 24 | 24 | IN
'000AAA' | 999777 | 2999331 | 26 | 26 | IN,OK
'AAA000' | 777999 | 2333997 | 24 | 24 | IN
'0AA0000' | 9779999 | 29339997 | 12 | 12 | MD
'AAA 0000' | 77709999 | 233129997 | 33 | 3 | MI,OH
'0AA A00' | 9770799 | 29312397 | 1 | 1 | MI
'000-AAA' | 9996777 | 29990331 | 7 | 7 | MN,NM
'00A-000' | 9976999 | 29930997 | 34 | 4 | NV
'000 0000' | 99909999 | 299729997 | 46 | 16 | NH
'A00-AAA' | 7996777 | 23990331 | 27 | 27 | NJ
'AAA-000' | 7776999 | 23330997 | 9 | 9 | NM,PR
'AAA-0000' | 77769999 | 233309997 | 23 | 23 | NY,NC,PA,TX,VA,WI
'000-000' | 9996999 | 29990997 | 15 | 15 | RI
'000 0AA' | 9990977 | 29972931 | 44 | 14 | SC
'A00-00A' | 7996997 | 23990991 | 29 | 29 | TN
'A00 0AA' | 7990977 | 23972931 | 17 | 17 | UT
状态编码
所有状态模式都连接到一个字符串中,每个模式均以小写字母结尾。空插槽中填充有任意x
。
[ [], [ 'MI' ], [ 'AZ', 'GA', 'WA' ], [ 'MI', 'OH' ], ... ] --> 'xMiAZGAWaMIOh...'
match(/[A-Z]*./g)
F(n)
最后,模式本身会转换为大写字母并分成2个字符的组。