blob: bf62ebaf3adfcb4fbe2bc760d4864f7410d09330 (
plain)
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
|
from string import ascii_lowercase, ascii_uppercase
from commons import get_input
removals = [''.join(x) for x in
list(zip(ascii_uppercase, ascii_lowercase)) + list(zip(ascii_lowercase, ascii_uppercase))]
inp = get_input(5)
def find_reduced_length(txt):
last = ""
while last != txt:
last = txt
for removal in removals:
txt = txt.replace(removal, '')
if txt != last:
break
return len(txt)
def find_best_removal(txt):
min_length = 1000000000
for ch in ascii_lowercase:
length = find_reduced_length(txt.replace(ch, '').replace(ch.upper(), ''))
if length < min_length:
min_length = length
return min_length
if __name__ == '__main__':
print("first:", find_reduced_length(inp))
print("second:", find_best_removal(inp))
|