|
@@ -10,24 +10,24 @@ salt = 'cuanljph'
|
10
|
10
|
|
11
|
11
|
@functools.lru_cache(maxsize=1024)
|
12
|
12
|
def md5(index):
|
13
|
|
- return hashlib.md5((salt + str(index)).encode('UTF-8')).hexdigest()
|
|
13
|
+ return hashlib.md5((salt + str(index)).encode('UTF-8')).hexdigest()
|
14
|
14
|
|
15
|
15
|
|
16
|
16
|
@functools.lru_cache(maxsize=1024)
|
17
|
17
|
def stretched(index):
|
18
|
|
- key = salt + str(index)
|
19
|
|
- for _ in range(2017): key = hashlib.md5(key.encode('UTF-8')).hexdigest()
|
20
|
|
- return key
|
|
18
|
+ key = salt + str(index)
|
|
19
|
+ for _ in range(2017): key = hashlib.md5(key.encode('UTF-8')).hexdigest()
|
|
20
|
+ return key
|
21
|
21
|
|
22
|
22
|
|
23
|
23
|
@functools.lru_cache(maxsize=1024)
|
24
|
24
|
def trip(index, fn):
|
25
|
|
- return tripmatcher.search(fn(index))
|
|
25
|
+ return tripmatcher.search(fn(index))
|
26
|
26
|
|
27
|
27
|
tripmatcher = re.compile(r'(.)\1{2}')
|
28
|
28
|
matches = lambda fn: ((i, fn(i)) for i in itertools.count()
|
29
|
|
- if trip(i, fn) and any(trip(i, fn).group(1) * 5 in fn(n)
|
30
|
|
- for n in range(i + 1, i + 1000)))
|
|
29
|
+ if trip(i, fn) and any(trip(i, fn).group(1) * 5 in fn(n)
|
|
30
|
+ for n in range(i + 1, i + 1000)))
|
31
|
31
|
|
32
|
32
|
print("Part one: %s" % next(itertools.islice(matches(md5), 63, 64))[0])
|
33
|
33
|
print("Part two: %s" % next(itertools.islice(matches(stretched), 63, 64))[0])
|