Files
  • main.py
main.py
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
parity_delay = 2

def seq(x, y):
    return parity_delay * x * 2 + y

matrix = [[None for _ in range(4)] for _ in range(3 * parity_delay)]

for i in range(parity_delay):
    a = i*2 + 1
    b = a + 1
    matrix[parity_delay * 0 + i] = [0, seq(0, a), seq(0, b), 0]
    matrix[parity_delay * 1 + i] = [seq(1, a), seq(1, b), 0, seq(2, a)]
    matrix[parity_delay * 2 + i] = [seq(2, b), 0, seq(3, a), seq(3, b)]

print('{}<Table>'.format(' '*8))
for i in range(0, 12 * parity_delay):
    row = int(i / 4)
    column = i % 4
    cell = "ABCD"[column] + str(row+1)
    offset = row // parity_delay + column
    sequence = row + (offset // 3) * parity_delay + 1

    if (offset % 3) == 0:
        print('{}<Block id="{}" sequence="{}">XorOfData</Block>'.format(' '*12, cell, sequence))
    else:
        print('{}<Block id="{}">{}</Block>'.format(' '*12, cell, matrix[row][column]))
print('{}</Table>'.format(' '*8))

rstudio_output = [[] for _ in range(4)]
rstudio_output[0] += ['{}<Sequences>'.format(' ' * 8)]
for i in range(parity_delay):
    a = i + 1
    b = parity_delay + i + 1
    c = parity_delay * 2 + i + 1
    d = parity_delay * 3 + i + 1
    rstudio_output[0] += ['{}<Sequence id="{}">A{} B{} C{}</Sequence>'.format(' ' * 12, a, a, a, a)]
    rstudio_output[1] += ['{}<Sequence id="{}">D{} A{} B{}</Sequence>'.format(' ' * 12, b, a, b, b)]
    rstudio_output[2] += ['{}<Sequence id="{}">C{} D{} A{}</Sequence>'.format(' ' * 12, c, b, b, c)]
    rstudio_output[3] += ['{}<Sequence id="{}">B{} C{} D{}</Sequence>'.format(' ' * 12, d, c, c, c)]
rstudio_output[3] += ['{}</Sequences>'.format(' ' * 8)]

for line_group in rstudio_output:
    for line in line_group:
        print(line)