-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmisc.py
193 lines (162 loc) · 3.53 KB
/
misc.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#encoding: utf8
from __future__ import unicode_literals
def sameChars(string):
pole = []
for i in string:
if i in pole:
return True
else:
pole.append(i)
return False
def arr2str(array):
string = ""
for i in array:
string = string + str(i)
return string
def str2arr(string):
arr = []
for i in string:
arr.append(int(i))
return arr
def sudoku2string(x):
s = ""
for i in x:
for j in i:
s = s+str(j)
return s
def string2sudoku(x):
sd = []
for i in range(0,9,1):
sd.append([])
for j in range(0,9,1):
sd[i].append(int(x[9*i+j]))
return sd
def cand2string(x):
output = ""
for i in range(0,9,1):
for j in range(0,9,1):
for k in x[i][j]:
output = output + str(k)
output = output + "|"
return output[:-1]
def string2cand(x):
output = []
x = x.split("|")
for i in range(0,9,1):
output.append([])
for j in range(0,9,1):
output[i].append([])
for k in x[9*i+j]:
output[i][j].append(int(k))
return output
def note2string(x):
output = ""
for i in range(0,9,1):
for j in range(0,9,1):
output = output + x[i][j]
output = output + "|"
return output[:-1]
def string2note(x):
x = x.split("|")
output = []
for i in range(0,9,1):
output.append([])
for j in range(0,9,1):
output[i].append(unicode(x[9*i+j]))
return output
def string2time(x):
x = x.split(":")
return int(x[0])*3600+int(x[1])*60+int(x[2])
def num2alpha(n):
if n == 0:
return "A"
if n == 1:
return "B"
if n == 2:
return "C"
if n == 3:
return "D"
if n == 4:
return "E"
if n == 5:
return "F"
if n == 6:
return "G"
if n == 7:
return "H"
if n == 8:
return "I"
return False
def alpha2num(char):
char = str(char)
if char.lower() == "a":
return 0
if char.lower() == "b":
return 1
if char.lower() == "c":
return 2
if char.lower() == "d":
return 3
if char.lower() == "e":
return 4
if char.lower() == "f":
return 5
if char.lower() == "g":
return 6
if char.lower() == "h":
return 7
if char.lower() == "i":
return 8
return -1
def hms(integer):
h = divmod(integer,3600)
zbytek = h[1]
h = h[0]
m = divmod(zbytek,60)
s = m[1]
m = m[0]
h = str(h)
if m < 10:
m = "0"+str(m)
else:
m = str(m)
if s < 10:
s = "0"+str(s)
else:
s = str(s)
return "Čas: "+h+":"+m+":"+s
def dekodovatCtverec(n):
if n == 0:
return "levém horním"
elif n == 1:
return "levém prostředním"
elif n == 2:
return "levém dolním"
elif n == 3:
return "prostředním horním"
elif n == 4:
return "prostředním"
elif n == 5:
return "prostředním dolním"
elif n == 6:
return "levém horním"
elif n == 7:
return "levém prostředním"
elif n == 8:
return "levém dolním"
def DB2list(x):
output = []
for i in x:
output.append(i[0])
return output
def wideDB2list(x):
output = []
for i in x:
output.append(i)
return output
def realWideDB2list(x):
output = []
for i in x:
for j in i:
output.append(j)
return output