Created
December 5, 2016 12:57
-
-
Save yi-jiayu/1a609560e36be8757440948bce637399 to your computer and use it in GitHub Desktop.
Day 3 solution for Advent of Code 2016 as it was when I submitted my answer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from hashlib import md5 | |
secret = 'reyedfim' | |
nonce = 0 | |
digits = [] | |
passwd = [None] * 8 | |
while not all(passwd): | |
hash = md5() | |
hash.update('{}{}'.format(secret, nonce).encode('utf-8')) | |
hex = hash.hexdigest() | |
# print(hex) | |
# print(hex[:5]) | |
if hex[:5] == '00000': | |
# print(hex[5]) | |
digits.append(hex[5]) | |
pos = hex[5] | |
char = hex[6] | |
print(pos, char) | |
print(pos.isdigit()) | |
if pos.isdigit() and 0 <= int(pos) < 8 and passwd[int(pos)] is None: | |
passwd[int(pos)] = char | |
print(passwd) | |
nonce += 1 | |
print(''.join(digits)) | |
print(passwd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment