-
Notifications
You must be signed in to change notification settings - Fork 0
/
AoC4.py
31 lines (28 loc) · 859 Bytes
/
AoC4.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
inputdata = open("input.txt")
total = 0
for line in inputdata:
split = line.rpartition("-")
name = split[0]
code = ''.join(sorted(split[0])).strip("-")
split = split[2].partition("[")
sid = int(split[0])
chk = split[2].rstrip("]\n")
counts = {}
for letter in set(code):
counts[letter] = code.count(letter)
test = sorted(counts.items())
test = sorted(test, key=lambda x:x[1], reverse=True)
match = ''.join(str(a) for a,b in test)[0:5]
if match == chk:
total += sid
decoded = ""
for char in name:
if char == "-":
decoded += " "
else:
for i in range(sid%26):
char = chr(ord(char)+1)
if char == '{': char = 'a'
decoded += char
print(sid, decoded)
print(total)