Created
July 12, 2019 12:13
pattern complexity test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys,os | |
# hardcoded aether ritual patterns | |
p = [''' | |
1,d | |
3,k | |
5,d | |
6,k | |
7,d | |
11,d | |
12,d | |
14,k | |
16,d | |
17,k | |
18,d | |
20,d | |
22,d | |
23, | |
''',''' | |
1,k | |
2,k | |
3,d | |
4,d | |
5,k | |
6,k | |
7,d | |
8,d | |
9,k | |
10,k | |
11,k | |
12,k | |
13,d | |
14,d | |
15,k | |
16,k | |
17,d | |
18,d | |
19,d | |
20,d | |
21,k | |
22,k | |
23,d | |
24,d | |
25,k | |
26,k | |
27,d | |
28,d | |
29,d | |
30, | |
''',''' | |
1,k | |
2,d | |
3,d | |
4,k | |
6,d | |
8,k | |
10,k | |
12,d | |
14,k | |
16,d | |
17,d | |
18,d | |
19,k | |
21,d | |
23,k | |
25,k | |
27,d | |
30, | |
''',''' | |
1,k | |
'''] | |
#pattern sequence | |
v = [0,0,1,1,1,1,2,2,2,2,1,1,1,1,0,0,3] | |
e = [] | |
for q in p: | |
r = [y.split(',') for y in q.split() if y] | |
for i in range(len(r)): | |
r[i][0] = int(r[i][0]) | |
s = r[i][1] | |
if s == 'd': | |
n = 0 | |
elif s == 'k': | |
n = 1 | |
else: | |
n = -1 | |
r[i][1] = n | |
e.append(r) | |
m = [] | |
n = 0 | |
for j in v: | |
last = 1 | |
for c in e[j]: | |
n += c[0] - last | |
last = c[0] | |
if c[1] >= 0: | |
m.append((n, c[1])) | |
c = [{},{}] | |
s = ''.join('k' if n[1] else 'd' for n in m) | |
a = [] | |
for i in range(1, len(m)): | |
p = [0,0] | |
for j in range(1, min(16, i + 1)): | |
for k in range(2): | |
if s[i - j:i] in c[k].keys(): | |
p[k] += j | |
if m[i][1] == 0: | |
p[0],p[1] = p[1],p[0] | |
# now p0 is chance to have incorrect note | |
if sum(p): | |
a.append(p[0] / (p[0] + p[1])) | |
else: | |
a.append(1) | |
for j in range (2): | |
for k in c[j].keys(): | |
c[j][k] *= 0.95 #memory decay | |
for j in range (1, min(16, i + 1)): | |
c[m[i][1]][s[i - j:i]] = 1 | |
print(a) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment