#!/bin/py n = 6 h = n // 2 + 1 f = open('plot_6') def chunks(gen, n): while True: chunk = [] for i in range(n): try: chunk.append(next(gen)) except StopIteration: return yield chunk def heap(a): n = len(a) c = [0]*n A = list(a) yield A i = 1 while i < n: if c[i] < i: if i % 2 == 0: temp = A[0] A[0] = A[i] A[i] = temp else: temp = A[c[i]] A[c[i]] = A[i] A[i] = temp yield A c[i] += 1 i = 1 else: c[i] = 0 i += 1 print('gen permutations') perms = tuple(map(tuple, heap(range(1, n + 1)))) print('read file') data = tuple([int(j.split()[-1]) for j in i] for i in chunks(f, h - 1)) f.close() print('convert to walls') walls = set() for i, wall in enumerate(data): wall = [perms[i] for i in wall] print(wall) if i > 20: exit() sums = list(range(1, h * (n - 1) + 2)) for row in wall: v = 0 for s in row[:-1]: v += s sums.remove(v) v = 0 r = [] for s in sums: r.append(s - v) v = s print(sums, r) wall.append(tuple(r)) walls.add(frozenset(wall)) walls = tuple(tuple(wall) for wall in walls) f = open('log_6_tuples', 'w') f.write(str(walls)) f.close()