-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday14.py
42 lines (32 loc) · 826 Bytes
/
day14.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
from hashlib import md5
from collections import deque
import re
from time import sleep
salt = "zpqevtbw"
# salt = "abc"
def get_hash(i, reps=2017):
global salt
string = salt + str(i)
for _ in range(reps):
string = md5(string.encode()).hexdigest()
return string
keys = []
index = 0
mem = deque([get_hash(i) for i in range(1001)])
# try to optimize code
while len(keys) < 64:
if index%1000 == 0: print(index)
hexhash = mem[0]
m = re.search(r"(\w)\1\1", hexhash)
if m != None:
ltr = m.group(1)
for i in range(1,1001):
h = mem[i]
if re.search(ltr*5, h) != None:
keys.append(index)
print(len(keys))
break
index += 1
mem.popleft()
mem.append(get_hash(1000+index))
print(keys[-1])