#!/usr/bin/env python3

# braille chars

chars = {
# 0:0x2800,
1:0x2801,
2:0x2802,
12:0x2803,
3:0x2804,
13:0x2805,
23:0x2806,
123:0x2807,
4:0x2808,
14:0x2809,
24:0x280A,
124:0x280B,
34:0x280C,
134:0x280D,
234:0x280E,
1234:0x280F,
5:0x2810,
15:0x2811,
25:0x2812,
125:0x2813,
35:0x2814,
135:0x2815,
235:0x2816,
1235:0x2817,
45:0x2818,
145:0x2819,
245:0x281A,
1245:0x281B,
345:0x281C,
1345:0x281D,
2345:0x281E,
12345:0x281F,
6:0x2820,
16:0x2821,
26:0x2822,
126:0x2823,
36:0x2824,
136:0x2825,
236:0x2826,
1236:0x2827,
46:0x2828,
146:0x2829,
246:0x282A,
1246:0x282B,
346:0x282C,
1346:0x282D,
2346:0x282E,
12346:0x282F,
56:0x2830,
156:0x2831,
256:0x2832,
1256:0x2833,
356:0x2834,
1356:0x2835,
2356:0x2836,
12356:0x2837,
456:0x2838,
1456:0x2839,
2456:0x283A,
12456:0x283B,
3456:0x283C,
13456:0x283D,
23456:0x283E,
123456:0x283F,
7:0x2840,
17:0x2841,
27:0x2842,
127:0x2843,
37:0x2844,
137:0x2845,
237:0x2846,
1237:0x2847,
47:0x2848,
147:0x2849,
247:0x284A,
1247:0x284B,
347:0x284C,
1347:0x284D,
2347:0x284E,
12347:0x284F,
57:0x2850,
157:0x2851,
257:0x2852,
1257:0x2853,
357:0x2854,
1357:0x2855,
2357:0x2856,
12357:0x2857,
457:0x2858,
1457:0x2859,
2457:0x285A,
12457:0x285B,
3457:0x285C,
13457:0x285D,
23457:0x285E,
123457:0x285F,
67:0x2860,
167:0x2861,
267:0x2862,
1267:0x2863,
367:0x2864,
1367:0x2865,
2367:0x2866,
12367:0x2867,
467:0x2868,
1467:0x2869,
2467:0x286A,
12467:0x286B,
3467:0x286C,
13467:0x286D,
23467:0x286E,
123467:0x286F,
567:0x2870,
1567:0x2871,
2567:0x2872,
12567:0x2873,
3567:0x2874,
13567:0x2875,
23567:0x2876,
123567:0x2877,
4567:0x2878,
14567:0x2879,
24567:0x287A,
124567:0x287B,
34567:0x287C,
134567:0x287D,
234567:0x287E,
1234567:0x287F,
8:0x2880,
18:0x2881,
28:0x2882,
128:0x2883,
38:0x2884,
138:0x2885,
238:0x2886,
1238:0x2887,
48:0x2888,
148:0x2889,
248:0x288A,
1248:0x288B,
348:0x288C,
1348:0x288D,
2348:0x288E,
12348:0x288F,
58:0x2890,
158:0x2891,
258:0x2892,
1258:0x2893,
358:0x2894,
1358:0x2895,
2358:0x2896,
12358:0x2897,
458:0x2898,
1458:0x2899,
2458:0x289A,
12458:0x289B,
3458:0x289C,
13458:0x289D,
23458:0x289E,
123458:0x289F,
68:0x28A0,
168:0x28A1,
268:0x28A2,
1268:0x28A3,
368:0x28A4,
1368:0x28A5,
2368:0x28A6,
12368:0x28A7,
468:0x28A8,
1468:0x28A9,
2468:0x28AA,
12468:0x28AB,
3468:0x28AC,
13468:0x28AD,
23468:0x28AE,
123468:0x28AF,
568:0x28B0,
1568:0x28B1,
2568:0x28B2,
12568:0x28B3,
3568:0x28B4,
13568:0x28B5,
23568:0x28B6,
123568:0x28B7,
4568:0x28B8,
14568:0x28B9,
24568:0x28BA,
124568:0x28BB,
34568:0x28BC,
134568:0x28BD,
234568:0x28BE,
1234568:0x28BF,
78:0x28C0,
178:0x28C1,
278:0x28C2,
1278:0x28C3,
378:0x28C4,
1378:0x28C5,
2378:0x28C6,
12378:0x28C7,
478:0x28C8,
1478:0x28C9,
2478:0x28CA,
12478:0x28CB,
3478:0x28CC,
13478:0x28CD,
23478:0x28CE,
123478:0x28CF,
578:0x28D0,
1578:0x28D1,
2578:0x28D2,
12578:0x28D3,
3578:0x28D4,
13578:0x28D5,
23578:0x28D6,
123578:0x28D7,
4578:0x28D8,
14578:0x28D9,
24578:0x28DA,
124578:0x28DB,
34578:0x28DC,
134578:0x28DD,
234578:0x28DE,
1234578:0x28DF,
678:0x28E0,
1678:0x28E1,
2678:0x28E2,
12678:0x28E3,
3678:0x28E4,
13678:0x28E5,
23678:0x28E6,
123678:0x28E7,
4678:0x28E8,
14678:0x28E9,
24678:0x28EA,
124678:0x28EB,
34678:0x28EC,
134678:0x28ED,
234678:0x28EE,
1234678:0x28EF,
5678:0x28F0,
15678:0x28F1,
25678:0x28F2,
125678:0x28F3,
35678:0x28F4,
135678:0x28F5,
235678:0x28F6,
1235678:0x28F7,
45678:0x28F8,
145678:0x28F9,
245678:0x28FA,
1245678:0x28FB,
345678:0x28FC,
1345678:0x28FD,
2345678:0x28FE,
12345678:0x28FF,
}
getkl = lambda x:len("%i" % x)
counts = [0] * 9
for i in sorted(chars.keys(), key=getkl):
	kl = getkl(i)
	counts[kl] += 1

counts = [i // 8 for i in counts[1:]]
# [0, 8, 28, 56, 70, 56, 28, 8, 1]
# counts = [1,3,4,0,4,3,1]
print(counts)

outputs = [""] * 8
for key_class, kl_count in enumerate(counts):
	key_idx = 0
	o_ptr = 0
	count = 0
	keys = list(chars.keys())
	while count < 8*kl_count:
		key = keys[key_idx]
		key_idx += 1
		if getkl(key) == key_class + 1:
			outputs[o_ptr] += chr(chars[key])	
			count += 1
			o_ptr += 1
			if o_ptr >= 8:
				o_ptr = 0

outputs = [""] * 8

keys = list(chars.keys())

any_ = lambda chrs:len(set(nb).intersection(chrs)) > 0
all_ = lambda chrs:len(set(nb).intersection(chrs)) == len(set(chrs))
no   = lambda chrs:len(set(nb).intersection(chrs)) == 0

i = 0
while i < len(keys):
	key = keys[i]
	nb = "%i" % key
	skipchar = False
	for c in "14":
		if c in nb:
			skipchar = True
			break
	if len(nb) > 1 or skipchar:
		skipchar = False
		i += 1
		continue
	outputs[0] += chr(chars[key])
	del(keys[i])

print(len(keys))


#14
#25
#36
#78

REMAP = "12453687"[::-1]

def remap(in_):
	out_ = 0
	for c in "%i" % in_:
		out_ += 1 << REMAP.index(c)
	return out_

outputs = [
	chr(0x2800) +
	"".join([chr(chars[key]) for key in sorted(chars.keys(), key=remap)])
]

with open("output", "w", encoding="utf8") as f:
	outputs = "\n".join(outputs)
	f.write(outputs)
