diff options
author | Dennis Kobert <dennis@kobert.dev> | 2020-01-05 22:39:18 +0100 |
---|---|---|
committer | Dennis Kobert <dennis@kobert.dev> | 2020-01-05 22:39:18 +0100 |
commit | d343b5e10ec2dbd526decbfa984168cf2509f48c (patch) | |
tree | 6d62761a15a93d70ba68214cdb4f6f64a2e96071 /data/parser.py | |
parent | c583ee4faa552962594f7d5bf9b57bf62b6db5c0 (diff) | |
parent | 492045e538cf806bb49631dfbbaabbd8b566147e (diff) |
Merge branch 'master' of kobert:/var/repos/babel
Diffstat (limited to 'data/parser.py')
-rw-r--r-- | data/parser.py | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/data/parser.py b/data/parser.py new file mode 100644 index 0000000..e5faa72 --- /dev/null +++ b/data/parser.py @@ -0,0 +1,74 @@ +#!/bin/py + +n = 8 +h = n // 2 + 1 +f = open('plot_8') + +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_8_tuples', 'w') +f.write(str(walls)) +f.close() |