summaryrefslogtreecommitdiff
path: root/data/parser.py
blob: e5faa72b8c1932ba888094538d30fa50ddef6983 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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()