-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5a.py
59 lines (40 loc) · 820 Bytes
/
5a.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
file_name = "5a.txt"
#ord Z is 90
def process(x):
pairs = []
letters = list(set([ord(i) for i in x]))
for i in letters:
if i > 90:
if (i - 32) in letters:
pairs.append( [chr(i), chr(i-32)])
best = 100000
for p in pairs:
reducedstring = x.replace(p[0],'').replace(p[1],'')
score = whit(reducedstring)
if score < best:
best = score
print( "best --> ", best )
return
def whit(x):
b = x[0]
x = x[1:]
while x:
if len(b) == 0:
b = b + x[0]
x = x[1:]
continue
if abs(ord(b[-1]) - ord(x[0])) == 32:
b = b[:-1]
x = x[1:]
continue
if abs(ord(b[-1]) - ord(x[0])) != 32:
b = b + x[0]
x = x[1:]
continue
return len(b) + len(x)
def main():
with open(file_name, 'r') as f:
x = f.readlines()
print(len(x))
process(x[0])
main()