-
Notifications
You must be signed in to change notification settings - Fork 0
/
type2 cca.py
153 lines (106 loc) · 3.08 KB
/
type2 cca.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
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import pandas as pd
import numpy as np
from itertools import *
import os
import sys
import time
dict={0: 0, 1: 100, 2: 101, 3: 10, 4: 11, 5: 110, 6: 111, 7: 120, 8: 121, 9: 210, 10: 211, 11: 220, 12: 221, 13: 330}
redict={0: 0, 100: 1, 101: 2, 10: 3, 11: 4, 110: 5, 111: 6, 120: 7, 121: 8, 210: 9, 211: 10, 220: 11, 221: 12, 330: 13}
def xor1(a,b):
c=tab[a][b]
d=index_to_list(c)
return d
def index_to_list(c):
c = dict[c]
d=[None] * 3
d[0] = c // 100
d[1] = (c % 100) // 10
d[2] = c % 10
return d
def list_to_index(a):
b=100*a[0]+10*a[1]+a[2]
c=redict[b]
return c
def rxor(a,b):
if a==[0,0,0] or a==[3,3,0]:
c=a
else:
c=a.copy()
c[2]=1
c=list_to_index(c)
b=list_to_index(b)
d=xor1(c,b)
return d
def rfc(state,d):
nst=[None]*d
for i in range(d):
if i%2==1:
nst[i]=rxor(state[i-2],state[i-1])
else:
nst[i]=state[i-1]
return nst
def main(d,round,index_x,index_ab):
state=[[0,0,0]for i in range(d)]
x=[1,0,0]
ab=[0, 1, 0]
state[index_x]=x
state[index_ab] = ab
list_state=[]
list_state.append(state)
for i in range(round):
state=rfc(state,d)
list_state.append(state)
maxround,list_index = judge(list_state,d)
return maxround,list_index,list_state
def judge(list,d):
length=len(list)-1
list1=[[1,1,0],[1,1,1],[1,2,0],[1,2,1],]
list2=[[0,0,0],[1,0,0],[0,1,0],[1,1,0],[0,1,1],[1,0,1],[2,1,0],[1,2,0],[2,2,0]]
list_index=[]
maxlength=0
for i in range(length,0,-1):
if i < maxlength:
break
for j in range(d):
if j%2==1:
if list[i-1][j-2] in list1 and list[i-1][j-1] in list2 :
maxlength=i
list_index.append([i,j])
return maxlength,list_index
def table():
df = pd.read_excel('R-rule.xlsx', sheet_name='Sheet2')
a = df.values
for i in range(len(a)):
for j in range(len(a[0])):
a[i, j] = redict[a[i][j]]
return a
def jiance(d,round):
l = [i for i in range(d)]
pailie = list(permutations(l, 2))
maxr=0
list_max=[]
for index_x,index_ab in pailie:
maxround,list_index,list_state=main(d, round, index_x, index_ab)
if maxround>maxr:
os.system('cls')
time.sleep(0.01)
maxr=maxround
list_max=[[[index_x,index_ab],list_index]]
print([index_x, index_ab],maxround)
for i in list_state:
print(i)
elif maxround==maxr:
list_max.append([[index_x,index_ab],list_index])
print([index_x, index_ab],maxround)
for i in list_state:
print(i)
print('\nmaxround',maxr)
print('max_list')
for i in list_max:
print(i)
return None
if __name__ == '__main__':
d=6
round=6
tab=table()
jiance(d,round)