From 85627bc39db56d1ca3dca747535afcf6fd9cdcdd Mon Sep 17 00:00:00 2001 From: natrixaeria Date: Sun, 5 Jan 2020 21:47:19 +0100 Subject: Create GpuSolver --- data/parser.py | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 data/parser.py (limited to 'data/parser.py') 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() -- cgit v1.2.3-70-g09d2