-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpermutations.py
47 lines (42 loc) · 1.08 KB
/
permutations.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
45
46
47
import main as base
import numpy as np
# random change to test
# also testing
def main():
# print(reduce("ABABABAB"))
for j in range(1, 17):
print(j)
l = perms(j)
for i in range(len(l)):
s = l[i]
if s != reduce(s): continue
n = base.h_str_to_mat(s)
if np.array_equal(n, base.I3): print(s)
def reduce(s):
result = s
for i in range(len(s)-2):
if s[i] == s[i+1] and s[i] == s[i+2]:
sBefore = s[:i]
sAfter = s[i+3:]
result = sBefore + sAfter
break
s = result
for i in range(len(s)-7):
if s[i:i+8] == "ABABABAB" or s[i:i+8] == "BABABABA":
result = s[:i] + s[i+8:]
if result != s:
return reduce(result)
else:
return result
def perms(length):
if length == 1:
return ["A", "B"]
else:
previous = perms(length-1)
result = []
for i in range(len(previous)):
result.append(previous[i]+"A")
result.append(previous[i]+"B")
return result
if __name__ == "__main__":
main()