Explorar o código

Randomly clean up 2015 day 4

Taddeus Kroes %!s(int64=2) %!d(string=hai) anos
pai
achega
d04b26f188
Modificáronse 1 ficheiros con 4 adicións e 13 borrados
  1. 4 13
      2015/04_adventcoin.py

+ 4 - 13
2015/04_adventcoin.py

@@ -1,16 +1,7 @@
 #!/usr/bin/env python3
 from hashlib import md5
+from itertools import count
 
-key = 'iwrupvqb'
-
-d = b'xxx'
-i = -1
-while d[0] + d[1] > 0 or d[2] > 0xf:
-    i += 1
-    d = md5((key + str(i)).encode('ascii')).digest()
-print(i)
-
-while sum(d[:3]) > 0:
-    i += 1
-    d = md5((key + str(i)).encode('ascii')).digest()
-print(i)
+hashes = ((i, md5(b'iwrupvqb%d' % i).hexdigest()) for i in count(0))
+print(next(i for i, h in hashes if h[:5] == '00000'))
+print(next(i for i, h in hashes if h[:6] == '000000'))