In [1]:
given = """
-9 - ◐ + ◀ - ◳ + ▥ + ◉
-9 - ◪ + ◰
-8 - ▦ - ◔
-7 + ▲ + ▣ - ◫ + ◲ - △ - ⌘
-6 - ◭ + ◩ + ▩ + ◈ + ◆ - ◑ - ◲ - △
-6 + ◵ - ◇
-6 - ◴ + ◆ - ▼ - ◒ + ▶
-5 - ◵ - ◇ + ■ + ◒ - ◷
-5 - ◵ + ◁ - ● + ○ - ◷
-5 + ▩ + ◍ + ◶ - ◑ + ◓ - ▧
-4 + ◭ + ▣ - ⌘
-3 + ◕ + ▽ - ◔ + ◮ + △
-3 + ◀ + ◫ - ◑ - ◲
-3 + ▤ - ◒ + □ + ▶
-3 + ◁
-1 - ◭ + ▲ + ▥ + ◲
-1 + ◩ - ◆ + ▼ - ▷
-1 - ◆ + ◨ - ▷ + ◒ + □
+0 + ◕ + ◭ + ▦ - ◆ + ▣ + ◫ + ◔ + □
+0 + ◧ + ◀ - ◪ - ◳ - ▥ - ▧
+0 + ▽ + ▦ + ▣ + △
+0 + ▦ + ◮ - △ - □
+0 - ◩ + ◴ - ◫ - ▷ + △ + □ - ▶
+0 - ◴ - ▷ - ▨
+0 + ◶ - ◳ - ◰ - ◉ + ✮ + ▧
+1 + ◕ - ◭ - ▲ + △
+1 - ◀ - ▩ + ◈ - ◫ + ◱ + ▧
+1 - ◩ + ▩ + ▼ - ◍
+2 + ◴ - ▩ - ◆ - ◫ - ▨
+2 - ◇ - ◁ + ●
+3 - ◧ - ◐ + ◪ - ◰ + ◉
+3 + ◧ + ◀ + ◲ + ⌘ + ◉
+3 + ◪ - ◓ - ◱ - ▧
+3 - ◆ - ◨ + ◔ - △ + ▶
+3 + ◇ + ● - ○
+3 - ◍ + ◶ + ◱
+4 + ◧ - ◳ - ◰
+4 - ▩ + ◓ - ◱ - ▨
+4 + ◬ - ◇ + ◷
+4 + ◨ - ■ - ◒
+5 + ▤ + ◨ - ■ + ● - ▷ - ▶
+6 + ▤ + ● - ◒
+8 - ◭ - ◀ + ◈ - ◫ - ▥ + ⌘
+8 + ◐ - ◪ - ◳ + ✮
+8 - ◀ - ◪ - ◶ + ◑ + ◱ + ◉
+9 - ◕ + ▦
+9 - ◧ + ◈ + ◑ - ▥ - ◲ - ◉ - ▧
+9 - ◩ - ◍ + ◫ + ◑ + ◱ - ▨
"""

In [2]:
import collections

counts = collections.Counter(given)

In [3]:
counts


Out[3]:
Counter({'\n': 49,
         ' ': 428,
         '+': 139,
         '-': 123,
         '0': 7,
         '1': 6,
         '2': 2,
         '3': 10,
         '4': 5,
         '5': 4,
         '6': 4,
         '7': 1,
         '8': 4,
         '9': 5,
         '⌘': 4,
         '■': 3,
         '□': 5,
         '▣': 4,
         '▤': 3,
         '▥': 5,
         '▦': 5,
         '▧': 6,
         '▨': 4,
         '▩': 6,
         '▲': 3,
         '△': 8,
         '▶': 5,
         '▷': 5,
         '▼': 3,
         '▽': 2,
         '◀': 7,
         '◁': 3,
         '◆': 7,
         '◇': 5,
         '◈': 4,
         '◉': 6,
         '○': 2,
         '◍': 4,
         '●': 5,
         '◐': 3,
         '◑': 6,
         '◒': 6,
         '◓': 3,
         '◔': 4,
         '◕': 4,
         '◧': 5,
         '◨': 4,
         '◩': 5,
         '◪': 6,
         '◫': 8,
         '◬': 1,
         '◭': 6,
         '◮': 2,
         '◰': 4,
         '◱': 6,
         '◲': 6,
         '◳': 5,
         '◴': 4,
         '◵': 3,
         '◶': 4,
         '◷': 3,
         '✮': 2})

In [4]:
len(counts)


Out[4]:
62

In [5]:
unicode = {}

for c in counts:
  if ord(c) > 100:
    unicode[c] = counts[c]

In [6]:
unicode


Out[6]:
{'⌘': 4,
 '■': 3,
 '□': 5,
 '▣': 4,
 '▤': 3,
 '▥': 5,
 '▦': 5,
 '▧': 6,
 '▨': 4,
 '▩': 6,
 '▲': 3,
 '△': 8,
 '▶': 5,
 '▷': 5,
 '▼': 3,
 '▽': 2,
 '◀': 7,
 '◁': 3,
 '◆': 7,
 '◇': 5,
 '◈': 4,
 '◉': 6,
 '○': 2,
 '◍': 4,
 '●': 5,
 '◐': 3,
 '◑': 6,
 '◒': 6,
 '◓': 3,
 '◔': 4,
 '◕': 4,
 '◧': 5,
 '◨': 4,
 '◩': 5,
 '◪': 6,
 '◫': 8,
 '◬': 1,
 '◭': 6,
 '◮': 2,
 '◰': 4,
 '◱': 6,
 '◲': 6,
 '◳': 5,
 '◴': 4,
 '◵': 3,
 '◶': 4,
 '◷': 3,
 '✮': 2}

In [7]:
for c, f in unicode.items():
  print('%s\t%s' % (c, f))


◐	3
◀	7
◳	5
▥	5
◉	6
◪	6
◰	4
▦	5
◔	4
▲	3
▣	4
◫	8
◲	6
△	8
⌘	4
◭	6
◩	5
▩	6
◈	4
◆	7
◑	6
◵	3
◇	5
◴	4
▼	3
◒	6
▶	5
■	3
◷	3
◁	3
●	5
○	2
◍	4
◶	4
◓	3
▧	6
◕	4
▽	2
◮	2
▤	3
□	5
▷	5
◨	4
◧	5
▨	4
✮	2
◱	6
◬	1

In [8]:
states = {}

state_sheet = """
◧	Arizona	AZ
✮	Washington	WA
◮	South Carolina	SC
◭	Arkansas	AR
◫	Missouri	MO
○	Rhode Island	RI
▷	Ohio	OH
●	New York	NY
◇	Massachusetts	MA
◱	South Dakota	SD
▲	Louisiana	LA
▦	Georgia	GA
◈	Kansas	KS
◨	Maryland	MD
◬	Maine	ME
⌘	Texas	TX
◴	Indiana	IN
▶	West Virginia	WV
△	Tennessee	TN
◉	Utah	UT
◕	Alabama	AL
◔	North Carolina	NC
◆	Kentucky	KY
▼	Michigan	MI
◪	Idaho	ID
▣	Mississippi	MS
◑	Nebraska	NE
▨	Wisconsin	WI
◩	Illinois	IL
◷	Vermont	VT
◳	Nevada	NV
▥	New Mexico	NM
◶	Montana	MT
□	Virginia	VA
◵	Connecticut	CT
◓	North Dakota	ND
◐	California	CA
◍	Minnesota	MN
◁	New Hampshire	NH
▤	Delaware	DE
◒	Pennsylvania	PA
■	New Jersey	NJ
◲	Oklahoma	OK
◰	Oregon	OR
▧	Wyoming	WY
▽	Florida	FL
◀	Colorado	CO
▩	Iowa	IA
"""
code_to_long = {}

state_n = []
for line in state_sheet.strip('\n').split('\n'):
  if not line.strip():
    state_n.append('???')
    continue
  symbol, state, xy = line.split('\t')
  if not symbol:
    state_n.append('???')
    continue
  state_n.append(xy)
  states[symbol] = xy
  code_to_long[]

print(states)


{'◧': 'AZ', '✮': 'WA', '◮': 'SC', '◭': 'AR', '◫': 'MO', '○': 'RI', '▷': 'OH', '●': 'NY', '◇': 'MA', '◱': 'SD', '▲': 'LA', '▦': 'GA', '◈': 'KS', '◨': 'MD', '◬': 'ME', '⌘': 'TX', '◴': 'IN', '▶': 'WV', '△': 'TN', '◉': 'UT', '◕': 'AL', '◔': 'NC', '◆': 'KY', '▼': 'MI', '◪': 'ID', '▣': 'MS', '◑': 'NE', '▨': 'WI', '◩': 'IL', '◷': 'VT', '◳': 'NV', '▥': 'NM', '◶': 'MT', '□': 'VA', '◵': 'CT', '◓': 'ND', '◐': 'CA', '◍': 'MN', '◁': 'NH', '▤': 'DE', '◒': 'PA', '■': 'NJ', '◲': 'OK', '◰': 'OR', '▧': 'WY', '▽': 'FL', '◀': 'CO', '▩': 'IA'}

In [9]:
replaced = given
for k, v in states.items():
  replaced = replaced.replace(k, '%s[x]' % v)
system = []
for i, line in enumerate(replaced.strip('\n').split('\n')):
  system.append('assign(%s, %s)' % (state_n[i], line))
replaced = '\n'.join(system)
print(replaced)


assign(AZ, -9 - CA[x] + CO[x] - NV[x] + NM[x] + UT[x])
assign(WA, -9 - ID[x] + OR[x])
assign(SC, -8 - GA[x] - NC[x])
assign(AR, -7 + LA[x] + MS[x] - MO[x] + OK[x] - TN[x] - TX[x])
assign(MO, -6 - AR[x] + IL[x] + IA[x] + KS[x] + KY[x] - NE[x] - OK[x] - TN[x])
assign(RI, -6 + CT[x] - MA[x])
assign(OH, -6 - IN[x] + KY[x] - MI[x] - PA[x] + WV[x])
assign(NY, -5 - CT[x] - MA[x] + NJ[x] + PA[x] - VT[x])
assign(MA, -5 - CT[x] + NH[x] - NY[x] + RI[x] - VT[x])
assign(SD, -5 + IA[x] + MN[x] + MT[x] - NE[x] + ND[x] - WY[x])
assign(LA, -4 + AR[x] + MS[x] - TX[x])
assign(GA, -3 + AL[x] + FL[x] - NC[x] + SC[x] + TN[x])
assign(KS, -3 + CO[x] + MO[x] - NE[x] - OK[x])
assign(MD, -3 + DE[x] - PA[x] + VA[x] + WV[x])
assign(ME, -3 + NH[x])
assign(TX, -1 - AR[x] + LA[x] + NM[x] + OK[x])
assign(IN, -1 + IL[x] - KY[x] + MI[x] - OH[x])
assign(WV, -1 - KY[x] + MD[x] - OH[x] + PA[x] + VA[x])
assign(TN, +0 + AL[x] + AR[x] + GA[x] - KY[x] + MS[x] + MO[x] + NC[x] + VA[x])
assign(UT, +0 + AZ[x] + CO[x] - ID[x] - NV[x] - NM[x] - WY[x])
assign(AL, +0 + FL[x] + GA[x] + MS[x] + TN[x])
assign(NC, +0 + GA[x] + SC[x] - TN[x] - VA[x])
assign(KY, +0 - IL[x] + IN[x] - MO[x] - OH[x] + TN[x] + VA[x] - WV[x])
assign(MI, +0 - IN[x] - OH[x] - WI[x])
assign(ID, +0 + MT[x] - NV[x] - OR[x] - UT[x] + WA[x] + WY[x])
assign(MS, +1 + AL[x] - AR[x] - LA[x] + TN[x])
assign(NE, +1 - CO[x] - IA[x] + KS[x] - MO[x] + SD[x] + WY[x])
assign(WI, +1 - IL[x] + IA[x] + MI[x] - MN[x])
assign(IL, +2 + IN[x] - IA[x] - KY[x] - MO[x] - WI[x])
assign(VT, +2 - MA[x] - NH[x] + NY[x])
assign(NV, +3 - AZ[x] - CA[x] + ID[x] - OR[x] + UT[x])
assign(NM, +3 + AZ[x] + CO[x] + OK[x] + TX[x] + UT[x])
assign(MT, +3 + ID[x] - ND[x] - SD[x] - WY[x])
assign(VA, +3 - KY[x] - MD[x] + NC[x] - TN[x] + WV[x])
assign(CT, +3 + MA[x] + NY[x] - RI[x])
assign(ND, +3 - MN[x] + MT[x] + SD[x])
assign(CA, +4 + AZ[x] - NV[x] - OR[x])
assign(MN, +4 - IA[x] + ND[x] - SD[x] - WI[x])
assign(NH, +4 + ME[x] - MA[x] + VT[x])
assign(DE, +4 + MD[x] - NJ[x] - PA[x])
assign(PA, +5 + DE[x] + MD[x] - NJ[x] + NY[x] - OH[x] - WV[x])
assign(NJ, +6 + DE[x] + NY[x] - PA[x])
assign(OK, +8 - AR[x] - CO[x] + KS[x] - MO[x] - NM[x] + TX[x])
assign(OR, +8 + CA[x] - ID[x] - NV[x] + WA[x])
assign(WY, +8 - CO[x] - ID[x] - MT[x] + NE[x] + SD[x] + UT[x])
assign(FL, +9 - AL[x] + GA[x])
assign(CO, +9 - AZ[x] + KS[x] + NE[x] - NM[x] - OK[x] - UT[x] - WY[x])
assign(IA, +9 - IL[x] - MN[x] + MO[x] + NE[x] + SD[x] - WI[x])

In [14]:
g = {}
for _, code in states.items():
  exec('%s = [0]' % code, g)

def print_states(everything=False):
  for xy in sorted(states.values()):
    if everything:
      print('%s = %s' % (xy, g[xy]))
    else:
      print('%s = %s' % (xy, g[xy][-1]))

def assign(state, value):
  state.append(value)

g['assign'] = assign
print_states()


AL = 0
AR = 0
AZ = 0
CA = 0
CO = 0
CT = 0
DE = 0
FL = 0
GA = 0
IA = 0
ID = 0
IL = 0
IN = 0
KS = 0
KY = 0
LA = 0
MA = 0
MD = 0
ME = 0
MI = 0
MN = 0
MO = 0
MS = 0
MT = 0
NC = 0
ND = 0
NE = 0
NH = 0
NJ = 0
NM = 0
NV = 0
NY = 0
OH = 0
OK = 0
OR = 0
PA = 0
RI = 0
SC = 0
SD = 0
TN = 0
TX = 0
UT = 0
VA = 0
VT = 0
WA = 0
WI = 0
WV = 0
WY = 0

In [15]:
iterations = 0
has_negative = True
while has_negative and iterations <= 5:
  has_negative = False
  if i % 1000000 == 0:
    print(iterations)
  exec('x = %s ; %s' % (iterations, replaced), g)
  iterations += 1
  for xy in states.values():
    if g[xy][-1] < 0:
      has_negative = True
      break

In [17]:
print_states()
print('x = %s\n%s' % (iterations, replaced))


AL = 4
AR = 0
AZ = 0
CA = 0
CO = 0
CT = 0
DE = 0
FL = 0
GA = 7
IA = 0
ID = 2
IL = 0
IN = 0
KS = 0
KY = 4
LA = 0
MA = 2
MD = 0
ME = 5
MI = 0
MN = 0
MO = 0
MS = 0
MT = 0
NC = 0
ND = 3
NE = 0
NH = 10
NJ = 0
NM = 0
NV = 0
NY = 7
OH = 2
OK = 0
OR = 0
PA = 0
RI = 0
SC = 8
SD = 2
TN = 0
TX = 0
UT = 0
VA = 0
VT = 7
WA = 0
WI = 0
WV = 2
WY = 3
x = 3
assign(AZ, -9 - CA[x] + CO[x] - NV[x] + NM[x] + UT[x])
assign(WA, -9 - ID[x] + OR[x])
assign(SC, -8 - GA[x] - NC[x])
assign(AR, -7 + LA[x] + MS[x] - MO[x] + OK[x] - TN[x] - TX[x])
assign(MO, -6 - AR[x] + IL[x] + IA[x] + KS[x] + KY[x] - NE[x] - OK[x] - TN[x])
assign(RI, -6 + CT[x] - MA[x])
assign(OH, -6 - IN[x] + KY[x] - MI[x] - PA[x] + WV[x])
assign(NY, -5 - CT[x] - MA[x] + NJ[x] + PA[x] - VT[x])
assign(MA, -5 - CT[x] + NH[x] - NY[x] + RI[x] - VT[x])
assign(SD, -5 + IA[x] + MN[x] + MT[x] - NE[x] + ND[x] - WY[x])
assign(LA, -4 + AR[x] + MS[x] - TX[x])
assign(GA, -3 + AL[x] + FL[x] - NC[x] + SC[x] + TN[x])
assign(KS, -3 + CO[x] + MO[x] - NE[x] - OK[x])
assign(MD, -3 + DE[x] - PA[x] + VA[x] + WV[x])
assign(ME, -3 + NH[x])
assign(TX, -1 - AR[x] + LA[x] + NM[x] + OK[x])
assign(IN, -1 + IL[x] - KY[x] + MI[x] - OH[x])
assign(WV, -1 - KY[x] + MD[x] - OH[x] + PA[x] + VA[x])
assign(TN, +0 + AL[x] + AR[x] + GA[x] - KY[x] + MS[x] + MO[x] + NC[x] + VA[x])
assign(UT, +0 + AZ[x] + CO[x] - ID[x] - NV[x] - NM[x] - WY[x])
assign(AL, +0 + FL[x] + GA[x] + MS[x] + TN[x])
assign(NC, +0 + GA[x] + SC[x] - TN[x] - VA[x])
assign(KY, +0 - IL[x] + IN[x] - MO[x] - OH[x] + TN[x] + VA[x] - WV[x])
assign(MI, +0 - IN[x] - OH[x] - WI[x])
assign(ID, +0 + MT[x] - NV[x] - OR[x] - UT[x] + WA[x] + WY[x])
assign(MS, +1 + AL[x] - AR[x] - LA[x] + TN[x])
assign(NE, +1 - CO[x] - IA[x] + KS[x] - MO[x] + SD[x] + WY[x])
assign(WI, +1 - IL[x] + IA[x] + MI[x] - MN[x])
assign(IL, +2 + IN[x] - IA[x] - KY[x] - MO[x] - WI[x])
assign(VT, +2 - MA[x] - NH[x] + NY[x])
assign(NV, +3 - AZ[x] - CA[x] + ID[x] - OR[x] + UT[x])
assign(NM, +3 + AZ[x] + CO[x] + OK[x] + TX[x] + UT[x])
assign(MT, +3 + ID[x] - ND[x] - SD[x] - WY[x])
assign(VA, +3 - KY[x] - MD[x] + NC[x] - TN[x] + WV[x])
assign(CT, +3 + MA[x] + NY[x] - RI[x])
assign(ND, +3 - MN[x] + MT[x] + SD[x])
assign(CA, +4 + AZ[x] - NV[x] - OR[x])
assign(MN, +4 - IA[x] + ND[x] - SD[x] - WI[x])
assign(NH, +4 + ME[x] - MA[x] + VT[x])
assign(DE, +4 + MD[x] - NJ[x] - PA[x])
assign(PA, +5 + DE[x] + MD[x] - NJ[x] + NY[x] - OH[x] - WV[x])
assign(NJ, +6 + DE[x] + NY[x] - PA[x])
assign(OK, +8 - AR[x] - CO[x] + KS[x] - MO[x] - NM[x] + TX[x])
assign(OR, +8 + CA[x] - ID[x] - NV[x] + WA[x])
assign(WY, +8 - CO[x] - ID[x] - MT[x] + NE[x] + SD[x] + UT[x])
assign(FL, +9 - AL[x] + GA[x])
assign(CO, +9 - AZ[x] + KS[x] + NE[x] - NM[x] - OK[x] - UT[x] - WY[x])
assign(IA, +9 - IL[x] - MN[x] + MO[x] + NE[x] + SD[x] - WI[x])

In [ ]: