Last active
March 17, 2018 23:44
-
-
Save oprypin/97263eddb9504f69c649 to your computer and use it in GitHub Desktop.
Analyzer for LYNE patterns
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import namedtuple, Counter | |
import urllib.request | |
Item = namedtuple('item', 'n l a b') | |
items = [] | |
for line in urllib.request.urlopen('http://blaxpirit.pythonanywhere.com/lyne/text'): | |
line = line.strip().decode('utf-8') | |
n, l, a, b = line.split() | |
n = int(n) | |
items.append(Item(n, l, a, b)) | |
def number_bits(bits): | |
return [int(b) for b in bits] | |
def format_bits(bits, w, h): | |
result = '' | |
it = (int(b) for b in bits) | |
for y in range(h): | |
for x in range(w): | |
yield '\N{BULLET}' | |
if x==w-1: | |
break | |
yield '\N{EM DASH}' if next(it) else ' ' | |
if y==h-1: | |
break | |
yield '\n' | |
for x in range(w): | |
yield '|' if next(it) else ' ' | |
if x==w-1: | |
break | |
a, b = next(it), next(it) | |
if a and b: yield 'X' | |
elif a: yield '\\' | |
elif b: yield '/' | |
else: yield ' ' | |
yield '\n' | |
for kind in 'ab': | |
sz = (2, 3) if kind=='a' else (3, 3) | |
l = len(getattr(items[0], kind)) | |
its = [getattr(it, kind) for it in items if it.l=='a'] | |
print("Total {}x{}s:".format(*sz), len(its)) | |
print("Unique {}x{}s:".format(*sz), len(set(its))) | |
print("Patterns that repeat:") | |
pattern_counts = Counter(its) | |
for k, n in pattern_counts.most_common(): | |
if n>1: | |
print('{k:2}: {n}'.format(k=k, n=n)) | |
print("Patterns that occur only once:", sum(1 for k, n in pattern_counts.items() if n==1)) | |
bit_counts = Counter() | |
for it in its: | |
for i, b in enumerate(it): | |
if b=='1': | |
bit_counts[i] += 1 | |
print("Bits used:") | |
for k, n in bit_counts.most_common(): | |
print('{k:2}: {n}'.format(k=k, n=n)) | |
r = ''.join('1' if bit_counts[i] else '0' for i in range(l)) | |
print("Only these are used:", r) | |
print(''.join(format_bits(r, *sz))) | |
print('--------') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Total 2x3s: 770 | |
Unique 2x3s: 78 | |
Patterns that repeat: | |
00011010010: 34 | |
10001010010: 34 | |
01011010011: 33 | |
10010000010: 32 | |
01000010011: 30 | |
01001010011: 26 | |
00011000011: 23 | |
01001010010: 23 | |
10011010011: 23 | |
01011010010: 23 | |
10001010011: 23 | |
01011001011: 21 | |
01010000010: 21 | |
11001010010: 19 | |
11011000010: 18 | |
10011010010: 18 | |
10001000011: 18 | |
00001001011: 17 | |
10001000010: 16 | |
11001010011: 15 | |
11010000011: 15 | |
01000000010: 15 | |
00001001010: 15 | |
00011001011: 15 | |
11011010011: 14 | |
00011001010: 14 | |
01001001011: 12 | |
01011001010: 12 | |
01001001010: 12 | |
11001000010: 11 | |
11000010010: 11 | |
00001000011: 10 | |
00001010011: 9 | |
10001001010: 9 | |
00011010011: 9 | |
10011000010: 9 | |
10011000011: 8 | |
00000010010: 8 | |
00001010010: 7 | |
11001001011: 7 | |
11011000011: 6 | |
11011010010: 6 | |
10011001010: 5 | |
01011000010: 4 | |
00011000010: 4 | |
00011011001: 4 | |
11001001010: 3 | |
01011000011: 3 | |
11010010010: 3 | |
01000000011: 3 | |
10011001011: 3 | |
11011001001: 2 | |
01010011010: 2 | |
01000010010: 2 | |
11011001010: 2 | |
11000011010: 2 | |
11001000011: 2 | |
01000001010: 2 | |
11001011000: 2 | |
10000010011: 2 | |
00010010011: 2 | |
Patterns that occur only once: 17 | |
Bits used: | |
9: 760 | |
4: 606 | |
3: 399 | |
1: 390 | |
6: 389 | |
10: 362 | |
0: 347 | |
7: 173 | |
Only these are used: 11011011011 | |
•—• | |
|/| | |
• • | |
|\| | |
•—• | |
-------- | |
Total 3x3s: 770 | |
Unique 3x3s: 769 | |
Patterns that repeat: | |
00001010001110101000: 2 | |
Patterns that occur only once: 768 | |
Bits used: | |
17: 382 | |
12: 382 | |
14: 381 | |
0: 380 | |
18: 378 | |
6: 378 | |
11: 373 | |
10: 370 | |
16: 368 | |
4: 361 | |
Only these are used: 10001010001110101110 | |
•—• • | |
/ \ | |
• •—• | |
|\|/| | |
•—• • |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment