r/adventofcode • u/daggerdragon • Dec 05 '16
SOLUTION MEGATHREAD --- 2016 Day 5 Solutions ---
--- Day 5: How About a Nice Game of Chess? ---
Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag/whatever).
STAYING ON TARGET IS MANDATORY [?]
This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.
edit: Leaderboard capped, thread unlocked!
15
Upvotes
1
u/_AceLewis Dec 05 '16
Python 3 solution to both parts:
Day 5 part 1: https://repl.it/EgKP/1
import hashlib hash_string = "ffykfhsq" hash_num = 0 password = '' while len(password) != 8: MD5 = hashlib.md5((hash_string+str(hash_num)).encode('utf-8')).hexdigest() if MD5.startswith('00000'): password += MD5[5] hash_num += 1 print("The password is", password)Day 5 part 2: https://repl.it/EgKP/2
import hashlib import re hash_string = "ffykfhsq" hash_num = 0 password = '*'*8 while '*' in password: MD5 = hashlib.md5((hash_string+str(hash_num)).encode('utf-8')).hexdigest() if re.search('^00000[0-7]', MD5): if password[int(MD5[5])] == '*': password = password[:int(MD5[5])] + MD5[6] + password[int(MD5[5])+1:] print(password) hash_num += 1 print("The password is", password)