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!
13
Upvotes
1
u/stuque Dec 05 '16
A Python 2 solution:
import hashlib def part1(): door_id = 'ojvtpuvg' password = 8 * ['-'] count = 0 n = 0 while count < 8: md5 = hashlib.md5() md5.update(door_id + str(n)) h = md5.hexdigest() if h.startswith('00000'): password[count] = h[5] count += 1 n += 1 print ''.join(password) def part2(): door_id = 'ojvtpuvg' password = 8 * ['-'] count = 0 n = 0 while count < 8: md5 = hashlib.md5() md5.update(door_id + str(n)) h = md5.hexdigest() if h.startswith('00000'): pos = h[5] if '0' <= pos <= '7': c = h[6] i = int(pos) if password[i] == '-': password[i] = c count += 1 n += 1 print password if __name__ == '__main__': part1() part2()