Skip to content

Instantly share code, notes, and snippets.

@yi-jiayu
Created December 5, 2016 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yi-jiayu/1a609560e36be8757440948bce637399 to your computer and use it in GitHub Desktop.
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
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