-
Notifications
You must be signed in to change notification settings - Fork 0
/
lottery副本.py
148 lines (147 loc) · 4.65 KB
/
lottery副本.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
# coding: utf-8
#pip install xltd
#pip install xlwt-future
#http://bbs.aicai.com/thread-597961-1-1.html
import xlrd
import xlwt
import random
if __name__ == "__main__":
srcName = raw_input("Enter your input: ");
threeAndOne = 0
threeAndZero =0
oneAndZero = 0
mainThree = 0
firstThree =0
secondThree =0
mainOne = 0
firstOne =0
secondOne =0
mainZero = 0
firstZero =0
secondZero =0
#染色
def isRed(num):
if(num>=1):
return True
def isBrown(num):
if(0.96<=num and num<=0.99):
return True
def isWhite(num):
if(0.9<=num and num<=0.95):
return True
def isBlue(num):
if(0.86<=num and num<=0.89):
return True
def isGreen(num):
if(num<=0.85):
return True
#求出舍弃之不符合的行后,距离赔付率最近的还有最远的两个的index
def nearest(a,b,c,target):
disa = abs(a-target)
disb = abs(b-target)
disc = abs(c-target)
if( disa==0 and disb==0):
return [0,0]
elif(disa==0 and disc==0):
return [1,1]
elif(disb==0 and disc==0):
return [3,3]
dic = [(disa,3),(disb,1),(disc,0)]
if(disa!=disb and disa!=disc and disb!=disc):
dic = sorted(dic, key=lambda x:x[0],reverse=True)
return [dic[0][1],dic[1][1]]
if(disa==disb):
if(disa<disc):
return [0,random.randrange(1,4,2)]
elif(disa>disc):
threeOrOne = random.randrange(1,4,2)
return [threeOrOne,4-threeOrOne]
elif(disb==disc):
if(disb<disa):
return [3,random.randrange(0,2)]
elif(disb>disa):
oneOrZero = random.randrange(0,2)
return [oneOrZero,1-oneOrZero]
elif(disa==disc):
if(disa<disb):
return [1,random.randrange(0,4,3)]
elif(disa>disb):
zeroOrThree = random.randrange(0,4,3)
return [zeroOrThree,3-zeroOrThree]
# data = xlrd.open_workbook("新浪爱彩(www.aicai.com)_指数数据_2016-2017_不来梅VS弗赖堡.xls")
data = xlrd.open_workbook(srcName)
table = data.sheets()[0]
nrows = table.nrows
ncols = table.ncols
for i in range(5 ,nrows-1 ):
table.row_values(i)
list = []
#从第五行开始整行读取
for rownum in range(5,nrows-1):
row = table.row_values(rownum)
if row:
app={}
app['zhu'] =row[11]
app['ping'] = row[12]
app['ke'] = row[13]
app['s'] = None
app['c'] = None
app['peifu'] =round( row[14]/100,4)
#如果是出现只有蓝色,或者只有灰色那么就舍弃
if(((isWhite(app['zhu']) or isBlue(app['zhu']))and
(isWhite(app['ping'])or isBlue(app['ping']))and
(isWhite(app['ke'])or isBlue(app['ke']))) or
((isWhite(app['zhu']) or isBrown(app['zhu']))and
(isWhite(app['ping'])or isBrown(app['ping']))and
(isWhite(app['ke'])or isBrown(app['ke'])))
):
continue
if(app['zhu']>app['peifu']):
app['zhu']=app['peifu']
if(app['ping']>app['peifu']):
app['ping']=app['peifu']
if(app['ke']>app['peifu']):
app['ke']=app['peifu']
appSC = nearest(app['zhu'],app['ping'],app['ke'],app['peifu'])
app['s']= appSC[0]
app['c']= appSC[1]
#统计结果
if(appSC[0]==3 and appSC[1]==3):
mainThree+=1
elif(appSC[0]==3 and appSC[1]==1):
threeAndOne+=1
firstThree+=1
secondOne+=1
elif(appSC[0]==3 and appSC[1]==0):
threeAndZero+=1
firstThree+=1
secondZero+=1
elif(appSC[0]==1 and appSC[1]==3):
threeAndOne+=1
firstOne+=1
secondThree+=1
elif(appSC[0]==1 and appSC[1]==1):
mainOne+=1
elif(appSC[0]==1 and appSC[1]==0):
oneAndZero+=1
firstOne+=1
secondZero+=1
elif(appSC[0]==0 and appSC[1]==3):
threeAndZero+=1
firstZero+=1
secondThree+=1
elif(appSC[0]==0 and appSC[1]==1):
oneAndZero+=1
firstZero+=1
secondOne+=1
elif(appSC[0]==0 and appSC[1]==0):
mainZero+=1
list.append(app)
print row[0],app
print " 3 1 0"
print "主选",mainThree,mainOne,mainZero
print "首选",firstThree,firstOne,firstZero
print "次选",secondThree,secondOne,secondZero
print "31:"+str(threeAndOne)
print "30:"+str(threeAndZero)
print "10:"+str(oneAndZero)