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]:
In [4]:
len(counts)
Out[4]:
In [5]:
unicode = {}
for c in counts:
if ord(c) > 100:
unicode[c] = counts[c]
In [6]:
unicode
Out[6]:
In [7]:
for c, f in unicode.items():
print('%s\t%s' % (c, f))
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)
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)
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()
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))
In [ ]: