blob: cfd72048fd9eb4bbfe6493f27aabdf31d9985194 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
sym = '◙'.encode('utf-8')
f = open('data/log_6', 'rb')
lines = []
for line in f:
if line.startswith(b'\x1b'):
line = line.replace(sym, b'x')
line = line.replace(b'\x1b[', b'')
line = line.replace(b'm', b'')
line = line.replace(b'\n', b'')
line = ''.join(' ' if chr(i).isdigit() else 'x' for i in line)
lines[-1].append(tuple(len(i) for i in line.split(' ') if i))
else:
lines.append([])
continue
f.close()
# f = open('log_6.py', 'w')
# f.write(str(walls))
# f.close()
def print_wall(wall):
for row in wall:
print('|'.join(' '.join(('.',) * stone) for stone in row))
walls = tuple(set(i) for i in lines if i)
n = len(next(iter(next(iter(walls)))))
h = (n // 2) + 1
for wall in []: #walls:
if tuple(range(1, n + 1)) in wall:
print_wall(wall)
print()
def for_stone(s):
counts = {w: 0 for w in range( (n - 1) * h + 1 )}
for wall in walls:
pos = 0
os = set()
for stone_index in range(n):
for row in wall:
os.add(sum(row[:row.index(s)]))
for c in os:
counts[c] += 1
return counts
all_counts = [for_stone(i + 1) for i in range(n)]
for sz, counts in enumerate(all_counts):
for xpos, count in counts.items(): #//in sorted(counts.items(), key=lambda i: -i[1]):
sz + 1, xpos, count
print(f'{sz + 1} {xpos} {count}')
print()
|