summaryrefslogtreecommitdiff
path: root/data/parser.py
diff options
context:
space:
mode:
Diffstat (limited to 'data/parser.py')
-rw-r--r--data/parser.py74
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()