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()