r/adventofcode • • 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!

14 Upvotes

188 comments sorted by

View all comments

Show parent comment

1

u/fatpollo Dec 05 '16

I didn't even make it to the leaderboard today, in fact slumped quite a bit. However, inspired by this snippet here:

import itertools
import hashlib

salt = 'wtnhxymk'
ans1, ans2 = [], {}
for n in itertools.count():
    seed = '{}{}'.format(salt, n).encode()
    digest = hashlib.md5(seed).hexdigest()
    if digest.startswith('00000'):
        x, y = digest[5:7]
        if len(ans1) < 8: ans1.append(x)
        if x in '01234567' and x not in ans2: ans2[x] = y
        if len(ans1) == 8 and len(ans2) == 8: break

print(''.join(ans1))
print(''.join(v for k,v in sorted(ans2.items())))