-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday_5.py
61 lines (46 loc) · 1.39 KB
/
day_5.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
f = open("files/day_5_input.txt")
text = f.read()
import operator
items = []
text_chars = []
for i in text:
items.append(i)
text_chars.append(i)
change = True
while(change):
change = False
for i in range(len(items)):
if(i+1<len(items)):
if( abs(ord(items[i]) - ord(items[i+1])) == 32 ):
del(items[i])
del(items[i])
change = True
print(len(items))
total_changes = {}
for j in range(97,122):
new_items = []
new_items = [x for x in text_chars]
change = True
total_change = 0
worst_ord = j
items_to_check = []
for i in range(len(new_items)):
try:
if( (ord(new_items[i])==worst_ord) or (ord(new_items[i])+32==worst_ord) ):
pass
else:
items_to_check.append(new_items[i])
except:
pass
while(change):
change = False
for i in range(len(items_to_check)):
if(i+1<len(items_to_check)):
if( (abs(ord(items_to_check[i]) - ord(items_to_check[i+1])) == 32) ):
del(items_to_check[i])
del(items_to_check[i])
change = True
total_change += 1
total_changes[j] = len(items_to_check)
global_max = min(total_changes.iteritems(),key=operator.itemgetter(1))
print(global_max)