Browse Source

Day 5

master
Chris Smith 7 years ago
parent
commit
e78f5879f9
1 changed files with 27 additions and 0 deletions
  1. 27
    0
      05.py

+ 27
- 0
05.py View File

@@ -0,0 +1,27 @@
1
+#!/usr/bin/python3
2
+
3
+import hashlib
4
+import itertools
5
+from multiprocessing import Pool
6
+
7
+door = 'abbhdwsy'
8
+
9
+def hash(x):
10
+    return hashlib.md5((door + str(x)).encode('utf-8')).hexdigest()
11
+
12
+pool = Pool()
13
+hashes = pool.imap(hash, itertools.count(), 10000)
14
+zeroes = (h for h in hashes if h.startswith('00000'))
15
+part1 = ''
16
+part2 = ['_'] * 8
17
+
18
+for h in zeroes:
19
+    if len(part1) < 8:
20
+        part1 += h[5]
21
+    if h[5].isdigit() and int(h[5]) < len(part2) and part2[int(h[5])] == '_':
22
+        part2[int(h[5])] = h[6]
23
+
24
+    if '_' not in part2:
25
+        print("Part one: %s" % part1)
26
+        print("Part two: %s" % ''.join(part2))
27
+        break

Loading…
Cancel
Save